diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index 3264f0da1c..3ae39c97f6 100755 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -24,6 +24,7 @@ import org.hibernate.ScrollMode; import org.hibernate.SessionException; import org.hibernate.StatelessSession; import org.hibernate.UnresolvableObjectException; +import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata; import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.internal.StatefulPersistenceContext; @@ -46,6 +47,7 @@ import org.hibernate.persister.entity.OuterJoinLoadable; import org.hibernate.pretty.MessageHelper; import org.hibernate.proxy.HibernateProxy; import org.hibernate.query.spi.ScrollableResultsImplementor; +import org.hibernate.tuple.entity.EntityMetamodel; /** * @author Gavin King @@ -298,12 +300,13 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen // first, check to see if we can use "bytecode proxies" - if ( allowBytecodeProxy - && persister.getEntityMetamodel().getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) { + final EntityMetamodel entityMetamodel = persister.getEntityMetamodel(); + final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata(); + if ( allowBytecodeProxy && bytecodeEnhancementMetadata.isEnhancedForLazyLoading() ) { // we cannot use bytecode proxy for entities with subclasses - if ( !persister.getEntityMetamodel().hasSubclasses() ) { - return persister.getBytecodeEnhancementMetadata().createEnhancedProxy( entityKey, false, this ); + if ( !entityMetamodel.hasSubclasses() ) { + return bytecodeEnhancementMetadata.createEnhancedProxy( entityKey, false, this ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/BytecodeEnhancementMetadataPojoImpl.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/BytecodeEnhancementMetadataPojoImpl.java index 20b07e995e..cab325745b 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/BytecodeEnhancementMetadataPojoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/BytecodeEnhancementMetadataPojoImpl.java @@ -18,6 +18,7 @@ import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributesMetadata; import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata; import org.hibernate.bytecode.spi.NotInstrumentedException; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -138,16 +139,17 @@ public class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhancementM public PersistentAttributeInterceptable createEnhancedProxy(EntityKey entityKey, boolean addEmptyEntry, SharedSessionContractImplementor session) { final EntityPersister persister = entityKey.getPersister(); final Serializable identifier = entityKey.getIdentifier(); + final PersistenceContext persistenceContext = session.getPersistenceContext(); // first, instantiate the entity instance to use as the proxy final PersistentAttributeInterceptable entity = (PersistentAttributeInterceptable) persister.getEntityTuplizer().instantiate( identifier, session ); // add the entity (proxy) instance to the PC - session.getPersistenceContext().addEnhancedProxy( entityKey, entity ); + persistenceContext.addEnhancedProxy( entityKey, entity ); // if requested, add the "holder entry" to the PC if ( addEmptyEntry ) { - session.getPersistenceContext().addEntry( + persistenceContext.addEntry( entity, Status.MANAGED, // loaded state