diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/PojoInstantiator.java b/hibernate-core/src/main/java/org/hibernate/tuple/PojoInstantiator.java index c218881e88..d4343fa958 100755 --- a/hibernate-core/src/main/java/org/hibernate/tuple/PojoInstantiator.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/PojoInstantiator.java @@ -50,7 +50,11 @@ public class PojoInstantiator implements Instantiator, Serializable { } public PojoInstantiator(Component component, ReflectionOptimizer.InstantiationOptimizer optimizer) { - this.mappedClass = component.getComponentClass(); + this( component.getComponentClass(), optimizer ); + } + + public PojoInstantiator(Class componentClass, ReflectionOptimizer.InstantiationOptimizer optimizer) { + this.mappedClass = componentClass; this.isAbstract = ReflectHelper.isAbstractClass( mappedClass ); this.optimizer = optimizer; diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java index 7404390916..d18b8bfe89 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractComponentTuplizer.java @@ -34,6 +34,7 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer { protected abstract Setter buildSetter(Component component, Property prop); protected AbstractComponentTuplizer(Component component) { + setComponentClass( component ); propertySpan = component.getPropertySpan(); getters = new Getter[propertySpan]; setters = new Setter[propertySpan]; @@ -102,4 +103,8 @@ public abstract class AbstractComponentTuplizer implements ComponentTuplizer { public Getter getGetter(int i) { return getters[i]; } + + // It should be an abstract method but not sure if this can break any customer extension + protected void setComponentClass(Component component){ + } } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java index 8931d16e17..dfbc512449 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/PojoComponentTuplizer.java @@ -22,7 +22,6 @@ import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl; import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.property.access.spi.Setter; -import org.hibernate.service.ServiceRegistry; import org.hibernate.tuple.Instantiator; import org.hibernate.tuple.PojoInstantiator; @@ -33,7 +32,7 @@ import org.hibernate.tuple.PojoInstantiator; * @author Steve Ebersole */ public class PojoComponentTuplizer extends AbstractComponentTuplizer { - private final Class componentClass; + private Class componentClass; private ReflectionOptimizer optimizer; private final Getter parentGetter; private final Setter parentSetter; @@ -41,8 +40,6 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { public PojoComponentTuplizer(Component component) { super( component ); - this.componentClass = component.getComponentClass(); - String[] getterNames = new String[propertySpan]; String[] setterNames = new String[propertySpan]; Class[] propTypes = new Class[propertySpan]; @@ -58,8 +55,6 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { parentGetter = null; } else { - final ServiceRegistry serviceRegistry = - component.getMetadata().getMetadataBuildingOptions().getServiceRegistry(); final PropertyAccess propertyAccess = PropertyAccessStrategyBasicImpl.INSTANCE.buildPropertyAccess( componentClass, parentPropertyName @@ -128,31 +123,36 @@ public class PojoComponentTuplizer extends AbstractComponentTuplizer { } protected Instantiator buildInstantiator(Component component) { - if ( component.isEmbedded() && ReflectHelper.isAbstractClass( component.getComponentClass() ) ) { - return new ProxiedInstantiator( component ); + if ( component.isEmbedded() && ReflectHelper.isAbstractClass( this.componentClass ) ) { + return new ProxiedInstantiator( this.componentClass ); } if ( optimizer == null ) { - return new PojoInstantiator( component, null ); + return new PojoInstantiator( this.componentClass, null ); } else { - return new PojoInstantiator( component, optimizer.getInstantiationOptimizer() ); + return new PojoInstantiator( this.componentClass, optimizer.getInstantiationOptimizer() ); } } protected Getter buildGetter(Component component, Property prop) { - return prop.getGetter( component.getComponentClass() ); + return prop.getGetter( this.componentClass ); } protected Setter buildSetter(Component component, Property prop) { - return prop.getSetter( component.getComponentClass() ); + return prop.getSetter( this.componentClass ); + } + + @Override + protected void setComponentClass(Component component) { + this.componentClass = component.getComponentClass(); } private static class ProxiedInstantiator implements Instantiator { private final Class proxiedClass; private final BasicProxyFactory factory; - public ProxiedInstantiator(Component component) { - proxiedClass = component.getComponentClass(); + public ProxiedInstantiator(Class componentClass) { + proxiedClass = componentClass; if ( proxiedClass.isInterface() ) { factory = Environment.getBytecodeProvider() .getProxyFactoryFactory()