diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/MonetaryAmountUserType.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/MonetaryAmountUserType.java index 32966c4a7e..7fb391e076 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/MonetaryAmountUserType.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/MonetaryAmountUserType.java @@ -9,10 +9,10 @@ package org.hibernate.userguide.mapping.basic; import java.io.Serializable; import java.math.BigDecimal; import java.util.Currency; -import java.util.function.Supplier; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.usertype.CompositeUserType; /** @@ -32,9 +32,15 @@ public class MonetaryAmountUserType implements CompositeUserType } @Override - public MonetaryAmount instantiate(Supplier valueSupplier, SessionFactoryImplementor sessionFactory) { - final Object[] values = valueSupplier.get(); - return new MonetaryAmount( (BigDecimal) values[0], (Currency) values[1] ); + public MonetaryAmount instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { + final BigDecimal amount = valueAccess.getValue(0, BigDecimal.class); + final Currency currency = valueAccess.getValue(1, Currency.class); + + if ( amount == null && currency == null ) { + return null; + } + + return new MonetaryAmount( amount, currency ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableCompositeUserTypeInstantiator.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableCompositeUserTypeInstantiator.java index bdf8cbf653..ab30b83ef2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableCompositeUserTypeInstantiator.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableCompositeUserTypeInstantiator.java @@ -6,10 +6,9 @@ */ package org.hibernate.metamodel.internal; -import java.util.function.Supplier; - import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.EmbeddableInstantiator; +import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.usertype.CompositeUserType; /** @@ -24,7 +23,7 @@ public class EmbeddableCompositeUserTypeInstantiator implements EmbeddableInstan } @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { + public Object instantiate(ValueAccess valuesAccess, SessionFactoryImplementor sessionFactory) { return userType.instantiate( valuesAccess, sessionFactory ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java index c948e8d224..35257a18c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorDynamicMap.java @@ -12,6 +12,7 @@ import java.util.function.Supplier; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.mapping.Component; import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.spi.ValueAccess; /** * Support for instantiating embeddables as dynamic-map representation @@ -31,12 +32,13 @@ public class EmbeddableInstantiatorDynamicMap } @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { + public Object instantiate(ValueAccess valuesAccess, SessionFactoryImplementor sessionFactory) { final Map dataMap = generateDataMap(); - if ( valuesAccess != null ) { + Object[] values = valuesAccess == null ? null : valuesAccess.getValues(); + if ( values != null ) { final EmbeddableMappingType mappingType = runtimeDescriptorAccess.get(); - mappingType.setValues( dataMap, valuesAccess.get() ); + mappingType.setValues( dataMap, values ); } return dataMap; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java index 7aa8c9cda3..8720233286 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoOptimized.java @@ -10,6 +10,7 @@ import java.util.function.Supplier; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.type.descriptor.java.JavaType; import static org.hibernate.bytecode.spi.ReflectionOptimizer.InstantiationOptimizer; @@ -32,10 +33,10 @@ public class EmbeddableInstantiatorPojoOptimized extends AbstractPojoInstantiato } @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { + public Object instantiate(ValueAccess valuesAccess, SessionFactoryImplementor sessionFactory) { final Object embeddable = instantiationOptimizer.newInstance(); final EmbeddableMappingType embeddableMapping = embeddableMappingAccess.get(); - embeddableMapping.setValues( embeddable, valuesAccess.get() ); + embeddableMapping.setValues( embeddable, valuesAccess.getValues() ); return embeddable; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java index c70460f33b..9af4e30ee2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorPojoStandard.java @@ -16,6 +16,7 @@ import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.type.descriptor.java.JavaType; /** @@ -47,7 +48,7 @@ public class EmbeddableInstantiatorPojoStandard extends AbstractPojoInstantiator } @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { + public Object instantiate(ValueAccess valuesAccess, SessionFactoryImplementor sessionFactory) { if ( isAbstract() ) { throw new InstantiationException( "Cannot instantiate abstract class or interface: ", getMappedPojoClass() @@ -60,11 +61,12 @@ public class EmbeddableInstantiatorPojoStandard extends AbstractPojoInstantiator try { if ( constructorInjection ) { - return constructor.newInstance( valuesAccess.get() ); + return constructor.newInstance( valuesAccess.getValues() ); } + Object[] values = valuesAccess == null ? null : valuesAccess.getValues(); final Object instance = constructor.newInstance(); - if ( valuesAccess != null ) { + if ( values != null ) { // At this point, createEmptyCompositesEnabled is always true. // We can only set the property values on the compositeInstance though if there is at least one non null value. // If the values are all null, we would normally not create a composite instance at all because no values exist. @@ -73,7 +75,7 @@ public class EmbeddableInstantiatorPojoStandard extends AbstractPojoInstantiator // A possible alternative could be to initialize the resolved values for primitive fields to their default value, // but that might cause unexpected outcomes for Hibernate 5 users that use createEmptyCompositesEnabled when updating. // You can see the need for this by running EmptyCompositeEquivalentToNullTest - embeddableMappingAccess.get().setValues( instance, valuesAccess.get() ); + embeddableMappingAccess.get().setValues( instance, values ); } return instance; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorProxied.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorProxied.java index afa06aba6d..a9921cb5f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorProxied.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/EmbeddableInstantiatorProxied.java @@ -11,6 +11,7 @@ import java.util.function.Supplier; import org.hibernate.bytecode.spi.BasicProxyFactory; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.mapping.EmbeddableMappingType; +import org.hibernate.metamodel.spi.ValueAccess; /** * EmbeddableInstantiator used for instantiating "proxies" of an embeddable. @@ -29,11 +30,12 @@ public class EmbeddableInstantiatorProxied implements StandardEmbeddableInstanti } @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { + public Object instantiate(ValueAccess valuesAccess, SessionFactoryImplementor sessionFactory) { final Object proxy = factory.getProxy(); - if ( valuesAccess != null ) { + Object[] values = valuesAccess == null ? null : valuesAccess.getValues(); + if ( values != null ) { final EmbeddableMappingType embeddableMapping = embeddableMappingAccess.get(); - embeddableMapping.setValues( proxy, valuesAccess.get() ); + embeddableMapping.setValues( proxy, values ); } return proxy; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java index b3d4bc194f..d983607950 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/VirtualIdRepresentationStrategy.java @@ -6,8 +6,6 @@ */ package org.hibernate.metamodel.mapping.internal; -import java.util.function.Supplier; - import org.hibernate.bytecode.spi.ProxyFactoryFactory; import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -22,6 +20,7 @@ import org.hibernate.metamodel.spi.EmbeddableInstantiator; import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy; import org.hibernate.metamodel.spi.EntityInstantiator; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.type.descriptor.java.JavaType; @@ -89,10 +88,10 @@ public class VirtualIdRepresentationStrategy implements EmbeddableRepresentation } @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { + public Object instantiate(ValueAccess valuesAccess, SessionFactoryImplementor sessionFactory) { final Object instantiated = entityInstantiator.instantiate( sessionFactory ); if ( valuesAccess != null ) { - final Object[] values = valuesAccess.get(); + final Object[] values = valuesAccess.getValues(); if ( values != null ) { virtualIdEmbeddable.setValues( instantiated, values ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EmbeddableInstantiator.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EmbeddableInstantiator.java index 1cbbd975ba..64299e1c5b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EmbeddableInstantiator.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/EmbeddableInstantiator.java @@ -26,6 +26,6 @@ public interface EmbeddableInstantiator extends Instantiator { /** * Create an instance of the embeddable */ - Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory); + Object instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ValueAccess.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ValueAccess.java new file mode 100644 index 0000000000..93ecc54875 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/ValueAccess.java @@ -0,0 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.metamodel.spi; + +import org.hibernate.Incubating; +import org.hibernate.engine.spi.SessionFactoryImplementor; + +/** + * + * @author Christian Beikov + */ +@Incubating +public interface ValueAccess { + Object[] getValues(); + + default T getValue(int i, Class clazz) { + return clazz.cast( getValues()[i] ); + } + + default Object getOwner() { + return null; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java index 5811b50c50..20fe462493 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/embeddable/AbstractEmbeddableInitializer.java @@ -22,6 +22,7 @@ import org.hibernate.metamodel.mapping.ForeignKeyDescriptor; import org.hibernate.metamodel.mapping.VirtualModelPart; import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy; +import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.proxy.HibernateProxy; import org.hibernate.query.spi.NavigablePath; @@ -43,7 +44,8 @@ import static org.hibernate.internal.util.collections.CollectionHelper.arrayList /** * @author Steve Ebersole */ -public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentAccess implements EmbeddableInitializer { +public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentAccess implements EmbeddableInitializer, + ValueAccess { private static final Object NULL_MARKER = new Object() { @Override public String toString() { @@ -205,12 +207,9 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA // NOTE: `valuesAccess` is set to null to indicate that all values are null, // as opposed to returning the all-null value array. the instantiator // interprets that as the values are not known or were all null. - final Supplier valuesAccess = stateAllNull - ? null - : () -> rowState; final Object target = representationStrategy .getInstantiator() - .instantiate( valuesAccess, sessionFactory); + .instantiate( this, sessionFactory); stateInjected = true; ( (HibernateProxy) compositeInstance ).getHibernateLazyInitializer().setImplementation( target ); } @@ -321,7 +320,7 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA final Supplier valuesAccess = stateAllNull == TRUE ? null : () -> rowState; - final Object instance = representationStrategy.getInstantiator().instantiate( valuesAccess, sessionFactory ); + final Object instance = representationStrategy.getInstantiator().instantiate( this, sessionFactory ); stateInjected = true; EmbeddableLoadingLogger.INSTANCE.debugf( "Created composite instance [%s] : %s", navigablePath, instance ); @@ -329,6 +328,21 @@ public abstract class AbstractEmbeddableInitializer extends AbstractFetchParentA return instance; } + @Override + public Object[] getValues() { + return stateAllNull ? null : rowState; + } + + @Override + public T getValue(int i, Class clazz) { + return stateAllNull ? null : clazz.cast( rowState[i] ); + } + + @Override + public Object getOwner() { + return fetchParentAccess.getInitializedInstance(); + } + private void handleParentInjection(RowProcessingState processingState) { // todo (6.0) : should we initialize the composite instance if we get here and it is null (not NULL_MARKER)? diff --git a/hibernate-core/src/main/java/org/hibernate/usertype/CompositeUserType.java b/hibernate-core/src/main/java/org/hibernate/usertype/CompositeUserType.java index 4b30a588aa..737684ff85 100644 --- a/hibernate-core/src/main/java/org/hibernate/usertype/CompositeUserType.java +++ b/hibernate-core/src/main/java/org/hibernate/usertype/CompositeUserType.java @@ -7,12 +7,12 @@ package org.hibernate.usertype; import java.io.Serializable; -import java.util.function.Supplier; import org.hibernate.HibernateException; import org.hibernate.Incubating; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.EmbeddableInstantiator; +import org.hibernate.metamodel.spi.ValueAccess; /** * A UserType that may be dereferenced in a query. @@ -51,7 +51,7 @@ public interface CompositeUserType extends EmbeddableInstantiator { Object getPropertyValue(J component, int property) throws HibernateException; @Override - J instantiate(Supplier values, SessionFactoryImplementor sessionFactory); + J instantiate(ValueAccess values, SessionFactoryImplementor sessionFactory); /** * The class that represents the embeddable mapping of the type. diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/MonetaryAmountInstantiator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/MonetaryAmountInstantiator.java index 4b825bdca8..4ebad346da 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/MonetaryAmountInstantiator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/MonetaryAmountInstantiator.java @@ -12,16 +12,16 @@ import java.util.function.Supplier; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.EmbeddableInstantiator; +import org.hibernate.metamodel.spi.ValueAccess; /** * @author Steve Ebersole */ public class MonetaryAmountInstantiator implements EmbeddableInstantiator { @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { - final Object[] values = valuesAccess.get(); - final BigDecimal amount = (BigDecimal) values[0]; - final Currency currency = (Currency) values[1]; + public Object instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { + final BigDecimal amount = valueAccess.getValue(0, BigDecimal.class); + final Currency currency = valueAccess.getValue(1, Currency.class); if ( amount == null && currency == null ) { return null; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/embeddable/NameInstantiator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/embeddable/NameInstantiator.java index 8f14e236b8..c4edc67da8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/embeddable/NameInstantiator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/embeddable/NameInstantiator.java @@ -6,21 +6,19 @@ */ package org.hibernate.orm.test.mapping.embeddable.strategy.instantiator.embeddable; -import java.util.function.Supplier; - import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.EmbeddableInstantiator; +import org.hibernate.metamodel.spi.ValueAccess; /** * @author Steve Ebersole */ public class NameInstantiator implements EmbeddableInstantiator { @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { - final Object[] values = valuesAccess.get(); + public Object instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { // alphabetical - final String first = (String) values[0]; - final String last = (String) values[1]; + final String first = valueAccess.getValue( 0, String.class ); + final String last = valueAccess.getValue( 1, String.class ); return new Name( first, last ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/embedded/NameInstantiator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/embedded/NameInstantiator.java index c777a12128..e9821dd52e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/embedded/NameInstantiator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/embedded/NameInstantiator.java @@ -6,21 +6,19 @@ */ package org.hibernate.orm.test.mapping.embeddable.strategy.instantiator.embedded; -import java.util.function.Supplier; - import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.EmbeddableInstantiator; +import org.hibernate.metamodel.spi.ValueAccess; /** * @author Steve Ebersole */ public class NameInstantiator implements EmbeddableInstantiator { @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { - final Object[] values = valuesAccess.get(); + public Object instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { // alphabetical - final String first = (String) values[0]; - final String last = (String) values[1]; + final String first = valueAccess.getValue( 0, String.class ); + final String last = valueAccess.getValue( 1, String.class ); return new Name( first, last ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/intf/NameInstantiator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/intf/NameInstantiator.java index 4ceb4631e8..b3c0b806a9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/intf/NameInstantiator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/intf/NameInstantiator.java @@ -6,21 +6,19 @@ */ package org.hibernate.orm.test.mapping.embeddable.strategy.instantiator.intf; -import java.util.function.Supplier; - import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.EmbeddableInstantiator; +import org.hibernate.metamodel.spi.ValueAccess; /** * @author Steve Ebersole */ public class NameInstantiator implements EmbeddableInstantiator { @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { - final Object[] values = valuesAccess.get(); + public Object instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { // alphabetical - final String first = (String) values[0]; - final String last = (String) values[1]; + final String first = valueAccess.getValue( 0, String.class ); + final String last = valueAccess.getValue( 1, String.class ); return new NameImpl( first, last ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/intf2/NameInstantiator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/intf2/NameInstantiator.java index 6accb3445f..ca13085df4 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/intf2/NameInstantiator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/intf2/NameInstantiator.java @@ -6,10 +6,9 @@ */ package org.hibernate.orm.test.mapping.embeddable.strategy.instantiator.intf2; -import java.util.function.Supplier; - import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.EmbeddableInstantiator; +import org.hibernate.metamodel.spi.ValueAccess; /** * @author Steve Ebersole @@ -18,10 +17,12 @@ public class NameInstantiator implements EmbeddableInstantiator { public static int callCount = 0; @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { + public Object instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { callCount++; - final Object[] values = valuesAccess.get(); - return Name.make( (String) values[0], (String) values[1] ); + // alphabetical + final String first = valueAccess.getValue( 0, String.class ); + final String last = valueAccess.getValue( 1, String.class ); + return Name.make( first, last ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/registered/NameInstantiator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/registered/NameInstantiator.java index c3bc64f815..ad6dc24201 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/registered/NameInstantiator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/embeddable/strategy/instantiator/registered/NameInstantiator.java @@ -6,21 +6,19 @@ */ package org.hibernate.orm.test.mapping.embeddable.strategy.instantiator.registered; -import java.util.function.Supplier; - import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.metamodel.spi.EmbeddableInstantiator; +import org.hibernate.metamodel.spi.ValueAccess; /** * @author Steve Ebersole */ public class NameInstantiator implements EmbeddableInstantiator { @Override - public Object instantiate(Supplier valuesAccess, SessionFactoryImplementor sessionFactory) { - final Object[] values = valuesAccess.get(); + public Object instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { // alphabetical - final String first = (String) values[0]; - final String last = (String) values[1]; + final String first = valueAccess.getValue( 0, String.class ); + final String last = valueAccess.getValue( 1, String.class ); return new Name( first, last ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/MonetaryAmountUserType.java b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/MonetaryAmountUserType.java index 8da361e5e3..f384cacae9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/MonetaryAmountUserType.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/MonetaryAmountUserType.java @@ -9,10 +9,10 @@ package org.hibernate.orm.test.sql.hand; import java.io.Serializable; import java.math.BigDecimal; import java.util.Currency; -import java.util.function.Supplier; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.usertype.CompositeUserType; /** @@ -35,9 +35,14 @@ public class MonetaryAmountUserType implements CompositeUserType } @Override - public MonetaryAmount instantiate(Supplier valueSupplier, SessionFactoryImplementor sessionFactory) { - final Object[] values = valueSupplier.get(); - return new MonetaryAmount( (BigDecimal) values[0], (Currency) values[1] ); + public MonetaryAmount instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { + final BigDecimal value = valueAccess.getValue(0, BigDecimal.class); + final Currency currency = valueAccess.getValue(1, Currency.class); + + if ( value == null && currency == null ) { + return null; + } + return new MonetaryAmount( value, currency ); } @Override diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserType.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserType.java index ed53469deb..8f48cfaac3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserType.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/integration/customtype/ObjectUserType.java @@ -7,10 +7,10 @@ package org.hibernate.envers.test.integration.customtype; import java.io.Serializable; -import java.util.function.Supplier; import org.hibernate.HibernateException; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.spi.ValueAccess; import org.hibernate.usertype.CompositeUserType; import jakarta.persistence.Lob; @@ -36,8 +36,8 @@ public class ObjectUserType implements CompositeUserType { } @Override - public Object instantiate(Supplier values, SessionFactoryImplementor sessionFactory) { - return values.get()[0]; + public Object instantiate(ValueAccess valueAccess, SessionFactoryImplementor sessionFactory) { + return valueAccess.getValue( 0, Object.class ); } @Override