From 2e81c322652750bb775ad650d0aa5e0f5c551a13 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Mon, 24 Jun 2019 18:31:40 +0100 Subject: [PATCH] HHH-13465 Allow inlined access to the PersistenceContext for internal methods --- .../internal/AbstractEntityInsertAction.java | 12 +++--- .../action/internal/CollectionAction.java | 2 +- .../internal/CollectionRecreateAction.java | 11 +++-- .../internal/CollectionRemoveAction.java | 14 ++++--- .../internal/CollectionUpdateAction.java | 8 ++-- .../action/internal/EntityAction.java | 2 +- .../action/internal/EntityDeleteAction.java | 10 +++-- .../internal/EntityIdentityInsertAction.java | 18 +++++--- .../action/internal/EntityInsertAction.java | 12 +++--- .../action/internal/EntityUpdateAction.java | 22 ++++++---- .../QueuedOperationCollectionAction.java | 2 +- .../UnresolvedEntityInsertActions.java | 2 +- ...EnhancementAsProxyLazinessInterceptor.java | 2 +- .../spi/interceptor/EnhancementHelper.java | 2 +- .../LazyAttributeLoadingInterceptor.java | 2 +- .../AbstractPersistentCollection.java | 26 ++++++------ ...timisticForceIncrementLockingStrategy.java | 2 +- .../lock/OptimisticLockingStrategy.java | 2 +- ...simisticForceIncrementLockingStrategy.java | 2 +- .../engine/internal/AbstractEntityEntry.java | 2 +- .../internal/BatchFetchQueueHelper.java | 2 +- .../hibernate/engine/internal/Cascade.java | 22 +++++----- .../engine/internal/Collections.java | 7 ++-- .../engine/internal/ForeignKeys.java | 8 ++-- .../internal/StatefulPersistenceContext.java | 2 +- .../engine/internal/TwoPhaseLoad.java | 33 +++++++-------- .../internal/CollectionLoadContext.java | 15 ++++--- .../engine/spi/CascadingActions.java | 2 +- .../hibernate/engine/spi/CollectionEntry.java | 2 +- .../hibernate/engine/spi/QueryParameters.java | 2 +- .../engine/spi/SessionDelegatorBaseImpl.java | 5 +++ .../spi/SharedSessionContractImplementor.java | 23 +++++++++- .../AbstractFlushingEventListener.java | 29 +++++++------ .../AbstractReassociateEventListener.java | 6 ++- .../internal/AbstractSaveEventListener.java | 23 ++++++---- .../DefaultAutoFlushEventListener.java | 6 ++- .../internal/DefaultDeleteEventListener.java | 14 ++++--- .../internal/DefaultEvictEventListener.java | 9 ++-- .../DefaultFlushEntityEventListener.java | 17 +++++--- .../internal/DefaultFlushEventListener.java | 8 ++-- ...aultInitializeCollectionEventListener.java | 17 ++++---- .../internal/DefaultLoadEventListener.java | 34 ++++++++------- .../internal/DefaultLockEventListener.java | 12 +++--- .../internal/DefaultMergeEventListener.java | 22 ++++++---- .../internal/DefaultPersistEventListener.java | 8 ++-- .../DefaultPostLoadEventListener.java | 12 +++--- .../internal/DefaultRefreshEventListener.java | 14 ++++--- .../DefaultReplicateEventListener.java | 15 ++++--- .../DefaultResolveNaturalIdEventListener.java | 12 ++++-- .../internal/DefaultSaveEventListener.java | 2 +- .../DefaultSaveOrUpdateEventListener.java | 27 +++++++----- .../internal/DefaultUpdateEventListener.java | 2 +- .../DirtyCollectionSearchVisitor.java | 2 +- .../event/internal/EvictVisitor.java | 15 ++++--- .../event/internal/FlushVisitor.java | 7 ++-- .../event/internal/MergeContext.java | 2 +- .../event/internal/OnReplicateVisitor.java | 2 +- .../PostUpdateEventListenerStandardImpl.java | 2 +- .../event/internal/ProxyVisitor.java | 11 ++--- .../hibernate/event/internal/WrapVisitor.java | 2 +- .../event/spi/AbstractCollectionEvent.java | 10 ++--- .../internal/AbstractScrollableResults.java | 8 ++-- .../org/hibernate/internal/CriteriaImpl.java | 2 +- .../org/hibernate/internal/IteratorImpl.java | 6 ++- .../internal/ScrollableResultsImpl.java | 2 +- .../org/hibernate/internal/SessionImpl.java | 17 +++++--- .../internal/StatelessSessionImpl.java | 13 ++++-- .../java/org/hibernate/loader/Loader.java | 30 +++++++------ ...cBatchingCollectionInitializerBuilder.java | 4 +- ...yBatchingCollectionInitializerBuilder.java | 2 +- ...dBatchingCollectionInitializerBuilder.java | 2 +- ...yBatchingCollectionInitializerBuilder.java | 14 ++++--- .../DynamicBatchingEntityLoaderBuilder.java | 10 ++--- .../LegacyBatchingEntityLoaderBuilder.java | 2 +- .../PaddedBatchingEntityLoaderBuilder.java | 2 +- .../LegacyBatchingEntityLoaderBuilder.java | 2 +- .../internal/AbstractLoadPlanBasedLoader.java | 2 +- .../CollectionReferenceInitializerImpl.java | 6 +-- .../EntityReferenceInitializerImpl.java | 42 +++++++++++-------- .../process/internal/EntityReturnReader.java | 2 +- .../ResultSetProcessingContextImpl.java | 6 ++- .../internal/ResultSetProcessorImpl.java | 13 +++--- .../AbstractCollectionPersister.java | 2 +- .../entity/AbstractEntityPersister.java | 39 +++++++++-------- .../persister/entity/NamedQueryLoader.java | 2 +- .../org/hibernate/pretty/MessageHelper.java | 2 +- .../PropertyAccessStrategyBackRefImpl.java | 2 +- ...ropertyAccessStrategyIndexBackRefImpl.java | 2 +- .../proxy/AbstractLazyInitializer.java | 12 +++--- .../query/internal/AbstractProducedQuery.java | 2 +- .../stat/internal/SessionStatisticsImpl.java | 8 ++-- .../tuple/entity/AbstractEntityTuplizer.java | 4 +- .../org/hibernate/type/CollectionType.java | 7 ++-- .../org/hibernate/type/ComponentType.java | 2 +- .../java/org/hibernate/type/EntityType.java | 2 +- .../org/hibernate/type/ManyToOneType.java | 10 +++-- .../java/org/hibernate/type/OneToOneType.java | 2 +- ...chFetchNotFoundIgnoreDefaultStyleTest.java | 2 +- .../AbstractDereferencedCollectionTest.java | 4 +- .../AggregatedCollectionEventListener.java | 2 +- .../BaseEnversCollectionEventListener.java | 2 +- .../relation/AbstractCollectionMapper.java | 2 +- 102 files changed, 541 insertions(+), 376 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/AbstractEntityInsertAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/AbstractEntityInsertAction.java index 6bc2095087..02be2cb4d9 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/AbstractEntityInsertAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/AbstractEntityInsertAction.java @@ -16,6 +16,7 @@ import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.spi.CachedNaturalIdValueSource; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.Status; import org.hibernate.persister.entity.EntityPersister; @@ -123,7 +124,7 @@ public abstract class AbstractEntityInsertAction extends EntityAction { public final void makeEntityManaged() { nullifyTransientReferencesIfNotAlready(); final Object version = Versioning.getVersion( getState(), getPersister() ); - getSession().getPersistenceContext().addEntity( + getSession().getPersistenceContextInternal().addEntity( getInstance(), ( getPersister().isMutable() ? Status.MANAGED : Status.READ_ONLY ), getState(), @@ -155,7 +156,7 @@ public abstract class AbstractEntityInsertAction extends EntityAction { // IMPL NOTE: non-flushed changes code calls this method with session == null... // guard against NullPointerException if ( session != null ) { - final EntityEntry entityEntry = session.getPersistenceContext().getEntry( getInstance() ); + final EntityEntry entityEntry = session.getPersistenceContextInternal().getEntry( getInstance() ); this.state = entityEntry.getLoadedState(); } } @@ -165,7 +166,7 @@ public abstract class AbstractEntityInsertAction extends EntityAction { */ protected void handleNaturalIdPreSaveNotifications() { // before save, we need to add a local (transactional) natural id cross-reference - getSession().getPersistenceContext().getNaturalIdHelper().manageLocalNaturalIdCrossReference( + getSession().getPersistenceContextInternal().getNaturalIdHelper().manageLocalNaturalIdCrossReference( getPersister(), getId(), state, @@ -180,9 +181,10 @@ public abstract class AbstractEntityInsertAction extends EntityAction { * @param generatedId The generated entity identifier */ public void handleNaturalIdPostSaveNotifications(Serializable generatedId) { + final PersistenceContext.NaturalIdHelper naturalIdHelper = getSession().getPersistenceContextInternal().getNaturalIdHelper(); if ( isEarlyInsert() ) { // with early insert, we still need to add a local (transactional) natural id cross-reference - getSession().getPersistenceContext().getNaturalIdHelper().manageLocalNaturalIdCrossReference( + naturalIdHelper.manageLocalNaturalIdCrossReference( getPersister(), generatedId, state, @@ -191,7 +193,7 @@ public abstract class AbstractEntityInsertAction extends EntityAction { ); } // after save, we need to manage the shared cache entries - getSession().getPersistenceContext().getNaturalIdHelper().manageSharedNaturalIdCrossReference( + naturalIdHelper.manageSharedNaturalIdCrossReference( getPersister(), generatedId, state, diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java index e8462168b0..aeea0b96d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionAction.java @@ -114,7 +114,7 @@ public abstract class CollectionAction implements Executable, Serializable, Comp Serializable finalKey = key; if ( key instanceof DelayedPostInsertIdentifier ) { // need to look it up from the persistence-context - finalKey = session.getPersistenceContext().getEntry( collection.getOwner() ).getId(); + finalKey = session.getPersistenceContextInternal().getEntry( collection.getOwner() ).getId(); if ( finalKey == key ) { // we may be screwed here since the collection action is about to execute // and we do not know the final owner key value diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionRecreateAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionRecreateAction.java index 4f86386627..b1823b8683 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionRecreateAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionRecreateAction.java @@ -18,6 +18,7 @@ import org.hibernate.event.spi.PostCollectionRecreateEventListener; import org.hibernate.event.spi.PreCollectionRecreateEvent; import org.hibernate.event.spi.PreCollectionRecreateEventListener; import org.hibernate.persister.collection.CollectionPersister; +import org.hibernate.stat.spi.StatisticsImplementor; /** * The action for recreating a collection @@ -47,13 +48,15 @@ public final class CollectionRecreateAction extends CollectionAction { final PersistentCollection collection = getCollection(); preRecreate(); - getPersister().recreate( collection, getKey(), getSession() ); - getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection ); + final SharedSessionContractImplementor session = getSession(); + getPersister().recreate( collection, getKey(), session); + session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection ); evict(); postRecreate(); - if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { - getSession().getFactory().getStatistics().recreateCollection( getPersister().getRole() ); + final StatisticsImplementor statistics = session.getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() ) { + statistics.recreateCollection( getPersister().getRole() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionRemoveAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionRemoveAction.java index 2620399529..5bcc5b5171 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionRemoveAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionRemoveAction.java @@ -19,6 +19,7 @@ import org.hibernate.event.spi.PostCollectionRemoveEventListener; import org.hibernate.event.spi.PreCollectionRemoveEvent; import org.hibernate.event.spi.PreCollectionRemoveEventListener; import org.hibernate.persister.collection.CollectionPersister; +import org.hibernate.stat.spi.StatisticsImplementor; /** * The action for removing a collection @@ -54,7 +55,7 @@ public final class CollectionRemoveAction extends CollectionAction { // the loaded owner will be set to null after the collection is removed, // so capture its value as the affected owner so it is accessible to // both pre- and post- events - this.affectedOwner = session.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection ); + this.affectedOwner = session.getPersistenceContextInternal().getLoadedCollectionOwnerOrNull( collection ); } /** @@ -88,24 +89,27 @@ public final class CollectionRemoveAction extends CollectionAction { public void execute() throws HibernateException { preRemove(); + final SharedSessionContractImplementor session = getSession(); + if ( !emptySnapshot ) { // an existing collection that was either non-empty or uninitialized // is replaced by null or a different collection // (if the collection is uninitialized, hibernate has no way of // knowing if the collection is actually empty without querying the db) - getPersister().remove( getKey(), getSession() ); + getPersister().remove( getKey(), session); } final PersistentCollection collection = getCollection(); if ( collection != null ) { - getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection ); + session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection ); } evict(); postRemove(); - if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { - getSession().getFactory().getStatistics().removeCollection( getPersister().getRole() ); + final StatisticsImplementor statistics = session.getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() ) { + statistics.removeCollection( getPersister().getRole() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionUpdateAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionUpdateAction.java index 39264ee6b8..8feb218d89 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionUpdateAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/CollectionUpdateAction.java @@ -20,6 +20,7 @@ import org.hibernate.event.spi.PreCollectionUpdateEvent; import org.hibernate.event.spi.PreCollectionUpdateEventListener; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.pretty.MessageHelper; +import org.hibernate.stat.spi.StatisticsImplementor; /** * The action for updating a collection @@ -88,12 +89,13 @@ public final class CollectionUpdateAction extends CollectionAction { persister.insertRows( collection, id, session ); } - getSession().getPersistenceContext().getCollectionEntry( collection ).afterAction( collection ); + session.getPersistenceContextInternal().getCollectionEntry( collection ).afterAction( collection ); evict(); postUpdate(); - if ( getSession().getFactory().getStatistics().isStatisticsEnabled() ) { - getSession().getFactory().getStatistics().updateCollection( getPersister().getRole() ); + final StatisticsImplementor statistics = session.getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() ) { + statistics.updateCollection( getPersister().getRole() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityAction.java index 90d9b41db5..b69f3deec2 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityAction.java @@ -101,7 +101,7 @@ public abstract class EntityAction */ public final Serializable getId() { if ( id instanceof DelayedPostInsertIdentifier ) { - final EntityEntry entry = session.getPersistenceContext().getEntry( instance ); + final EntityEntry entry = session.getPersistenceContextInternal().getEntry( instance ); final Serializable eeId = entry == null ? null : entry.getId(); return eeId instanceof DelayedPostInsertIdentifier ? null : eeId; } diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java index 666d551c0b..32af963676 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityDeleteAction.java @@ -24,6 +24,7 @@ import org.hibernate.event.spi.PostDeleteEventListener; import org.hibernate.event.spi.PreDeleteEvent; import org.hibernate.event.spi.PreDeleteEventListener; import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.stat.spi.StatisticsImplementor; /** * The action for performing an entity deletion. @@ -61,7 +62,7 @@ public class EntityDeleteAction extends EntityAction { this.state = state; // before remove we need to remove the local (transactional) natural id cross-reference - naturalIdValues = session.getPersistenceContext().getNaturalIdHelper().removeLocalNaturalIdCrossReference( + naturalIdValues = session.getPersistenceContextInternal().getNaturalIdHelper().removeLocalNaturalIdCrossReference( getPersister(), getId(), state @@ -103,7 +104,7 @@ public class EntityDeleteAction extends EntityAction { // After actually deleting a row, record the fact that the instance no longer // exists on the database (needed for identity-column key generation), and // remove it from the session cache - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final EntityEntry entry = persistenceContext.removeEntry( instance ); if ( entry == null ) { throw new AssertionFailure( "possible nonthreadsafe access to session" ); @@ -121,8 +122,9 @@ public class EntityDeleteAction extends EntityAction { postDelete(); - if ( getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto ) { - getSession().getFactory().getStatistics().deleteEntity( getPersister().getEntityName() ); + final StatisticsImplementor statistics = getSession().getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() && !veto ) { + statistics.deleteEntity( getPersister().getEntityName() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityIdentityInsertAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityIdentityInsertAction.java index 9763cc8ba4..1276bdc218 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityIdentityInsertAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityIdentityInsertAction.java @@ -11,8 +11,10 @@ import java.io.Serializable; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.event.service.spi.EventListenerGroup; +import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventType; import org.hibernate.event.spi.PostCommitInsertEventListener; import org.hibernate.event.spi.PostInsertEvent; @@ -20,6 +22,7 @@ import org.hibernate.event.spi.PostInsertEventListener; import org.hibernate.event.spi.PreInsertEvent; import org.hibernate.event.spi.PreInsertEventListener; import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.stat.spi.StatisticsImplementor; /** * The action for performing entity insertions when entity is using IDENTITY column identifier generation @@ -85,9 +88,10 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction //need to do that here rather than in the save event listener to let //the post insert events to have a id-filled entity when IDENTITY is used (EJB3) persister.setIdentifier( instance, generatedId, session ); - session.getPersistenceContext().registerInsertedKey( getPersister(), generatedId ); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + persistenceContext.registerInsertedKey( getPersister(), generatedId ); entityKey = session.generateEntityKey( generatedId, persister ); - session.getPersistenceContext().checkUniqueness( entityKey, getInstance() ); + persistenceContext.checkUniqueness( entityKey, getInstance() ); } @@ -101,8 +105,9 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction postInsert(); - if ( session.getFactory().getStatistics().isStatisticsEnabled() && !isVeto() ) { - session.getFactory().getStatistics().insertEntity( getPersister().getEntityName() ); + final StatisticsImplementor statistics = session.getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() && !isVeto() ) { + statistics.insertEntity( getPersister().getEntityName() ); } markExecuted(); @@ -137,8 +142,9 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction } private void postInsert() { + final EventSource eventSource = eventSource(); if ( isDelayed ) { - getSession().getPersistenceContext().replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId ); + eventSource.getPersistenceContextInternal().replaceDelayedEntityIdentityInsertKeys( delayedEntityKey, generatedId ); } final EventListenerGroup listenerGroup = listenerGroup( EventType.POST_INSERT ); @@ -150,7 +156,7 @@ public final class EntityIdentityInsertAction extends AbstractEntityInsertAction generatedId, getState(), getPersister(), - eventSource() + eventSource ); for ( PostInsertEventListener listener : listenerGroup.listeners() ) { listener.onPostInsert( event ); diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java index 1d83142def..d6bf42bb40 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityInsertAction.java @@ -28,6 +28,7 @@ import org.hibernate.event.spi.PreInsertEvent; import org.hibernate.event.spi.PreInsertEventListener; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.stat.internal.StatsHelper; +import org.hibernate.stat.spi.StatisticsImplementor; /** * The action for performing an entity insertion, for entities not defined to use IDENTITY generation. @@ -88,7 +89,7 @@ public final class EntityInsertAction extends AbstractEntityInsertAction { if ( !veto ) { persister.insert( id, getState(), instance, session ); - PersistenceContext persistenceContext = session.getPersistenceContext(); + PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final EntityEntry entry = persistenceContext.getEntry( instance ); if ( entry == null ) { throw new AssertionFailure( "possible non-threadsafe access to session" ); @@ -109,6 +110,7 @@ public final class EntityInsertAction extends AbstractEntityInsertAction { final SessionFactoryImplementor factory = session.getFactory(); + final StatisticsImplementor statistics = factory.getStatistics(); if ( isCachePutEnabled( persister, session ) ) { final CacheEntry ce = persister.buildCacheEntry( instance, @@ -122,8 +124,8 @@ public final class EntityInsertAction extends AbstractEntityInsertAction { final boolean put = cacheInsert( persister, ck ); - if ( put && factory.getStatistics().isStatisticsEnabled() ) { - factory.getStatistics().entityCachePut( + if ( put && statistics.isStatisticsEnabled() ) { + statistics.entityCachePut( StatsHelper.INSTANCE.getRootEntityRole( persister ), cache.getRegion().getName() ); @@ -134,8 +136,8 @@ public final class EntityInsertAction extends AbstractEntityInsertAction { postInsert(); - if ( factory.getStatistics().isStatisticsEnabled() && !veto ) { - factory.getStatistics().insertEntity( getPersister().getEntityName() ); + if ( statistics.isStatisticsEnabled() && !veto ) { + statistics.insertEntity( getPersister().getEntityName() ); } markExecuted(); diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java index fd9655369d..13a69241cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/EntityUpdateAction.java @@ -17,6 +17,7 @@ import org.hibernate.cache.spi.entry.CacheEntry; import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.spi.CachedNaturalIdValueSource; import org.hibernate.engine.spi.EntityEntry; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionEventListenerManager; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -30,6 +31,7 @@ import org.hibernate.event.spi.PreUpdateEvent; import org.hibernate.event.spi.PreUpdateEventListener; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.stat.internal.StatsHelper; +import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.type.TypeHelper; /** @@ -84,7 +86,7 @@ public final class EntityUpdateAction extends EntityAction { this.rowId = rowId; this.previousNaturalIdValues = determinePreviousNaturalIdValues( persister, previousState, session, id ); - session.getPersistenceContext().getNaturalIdHelper().manageLocalNaturalIdCrossReference( + session.getPersistenceContextInternal().getNaturalIdHelper().manageLocalNaturalIdCrossReference( persister, id, state, @@ -102,11 +104,12 @@ public final class EntityUpdateAction extends EntityAction { return null; } + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); if ( previousState != null ) { - return session.getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( previousState, persister ); + return persistenceContext.getNaturalIdHelper().extractNaturalIdValues( previousState, persister ); } - return session.getPersistenceContext().getNaturalIdSnapshot( id, persister ); + return persistenceContext.getNaturalIdSnapshot( id, persister ); } @Override @@ -156,7 +159,7 @@ public final class EntityUpdateAction extends EntityAction { ); } - final EntityEntry entry = session.getPersistenceContext().getEntry( instance ); + final EntityEntry entry = session.getPersistenceContextInternal().getEntry( instance ); if ( entry == null ) { throw new AssertionFailure( "possible nonthreadsafe access to session" ); } @@ -185,6 +188,7 @@ public final class EntityUpdateAction extends EntityAction { entry.postUpdate( instance, state, nextVersion ); } + final StatisticsImplementor statistics = factory.getStatistics(); if ( persister.canWriteToCache() ) { if ( persister.isCacheInvalidationRequired() || entry.getStatus()!= Status.MANAGED ) { persister.getCacheAccessStrategy().remove( session, ck); @@ -195,8 +199,8 @@ public final class EntityUpdateAction extends EntityAction { cacheEntry = persister.getCacheEntryStructure().structure( ce ); final boolean put = cacheUpdate( persister, previousVersion, ck ); - if ( put && factory.getStatistics().isStatisticsEnabled() ) { - factory.getStatistics().entityCachePut( + if ( put && statistics.isStatisticsEnabled() ) { + statistics.entityCachePut( StatsHelper.INSTANCE.getRootEntityRole( persister ), getPersister().getCacheAccessStrategy().getRegion().getName() ); @@ -204,7 +208,7 @@ public final class EntityUpdateAction extends EntityAction { } } - session.getPersistenceContext().getNaturalIdHelper().manageSharedNaturalIdCrossReference( + session.getPersistenceContextInternal().getNaturalIdHelper().manageSharedNaturalIdCrossReference( persister, id, state, @@ -214,8 +218,8 @@ public final class EntityUpdateAction extends EntityAction { postUpdate(); - if ( factory.getStatistics().isStatisticsEnabled() && !veto ) { - factory.getStatistics().updateEntity( getPersister().getEntityName() ); + if ( statistics.isStatisticsEnabled() && !veto ) { + statistics.updateEntity( getPersister().getEntityName() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/QueuedOperationCollectionAction.java b/hibernate-core/src/main/java/org/hibernate/action/internal/QueuedOperationCollectionAction.java index 532b12e377..01668ac5f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/QueuedOperationCollectionAction.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/QueuedOperationCollectionAction.java @@ -54,7 +54,7 @@ public final class QueuedOperationCollectionAction extends CollectionAction { // The other CollectionAction types call CollectionEntry#afterAction, which // clears the dirty flag. We don't want to call CollectionEntry#afterAction unless // there is no other CollectionAction that will be executed on the same collection. - final CollectionEntry ce = getSession().getPersistenceContext().getCollectionEntry( getCollection() ); + final CollectionEntry ce = getSession().getPersistenceContextInternal().getCollectionEntry( getCollection() ); if ( !ce.isDoremove() && !ce.isDoupdate() && !ce.isDorecreate() ) { ce.afterAction( getCollection() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/action/internal/UnresolvedEntityInsertActions.java b/hibernate-core/src/main/java/org/hibernate/action/internal/UnresolvedEntityInsertActions.java index 7f74080897..a75610bc5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/internal/UnresolvedEntityInsertActions.java +++ b/hibernate-core/src/main/java/org/hibernate/action/internal/UnresolvedEntityInsertActions.java @@ -181,7 +181,7 @@ public class UnresolvedEntityInsertActions { */ @SuppressWarnings({ "unchecked" }) public Set resolveDependentActions(Object managedEntity, SessionImplementor session) { - final EntityEntry entityEntry = session.getPersistenceContext().getEntry( managedEntity ); + final EntityEntry entityEntry = session.getPersistenceContextInternal().getEntry( managedEntity ); if ( entityEntry.getStatus() != Status.MANAGED && entityEntry.getStatus() != Status.READ_ONLY ) { throw new IllegalArgumentException( "EntityEntry did not have status MANAGED or READ_ONLY: " + entityEntry ); } diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementAsProxyLazinessInterceptor.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementAsProxyLazinessInterceptor.java index 653f4604aa..250b89b9ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementAsProxyLazinessInterceptor.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementAsProxyLazinessInterceptor.java @@ -183,7 +183,7 @@ public class EnhancementAsProxyLazinessInterceptor extends AbstractLazyLoadInter if ( isTemporarySession ) { // Add an entry for this entity in the PC of the temp Session - session.getPersistenceContext().addEntity( + session.getPersistenceContextInternal().addEntity( target, Status.READ_ONLY, // loaded state diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java index a958e5e8f9..91d865ac49 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/EnhancementHelper.java @@ -210,7 +210,7 @@ public class EnhancementHelper { final SessionFactoryImplementor sf = (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.getSessionFactory( interceptor.getSessionFactoryUuid() ); final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession(); - session.getPersistenceContext().setDefaultReadOnly( true ); + session.getPersistenceContextInternal().setDefaultReadOnly( true ); session.setHibernateFlushMode( FlushMode.MANUAL ); return session; } diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributeLoadingInterceptor.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributeLoadingInterceptor.java index dbc13df32e..74d58a7d96 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributeLoadingInterceptor.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/spi/interceptor/LazyAttributeLoadingInterceptor.java @@ -87,7 +87,7 @@ public class LazyAttributeLoadingInterceptor extends AbstractLazyLoadInterceptor final Object[] loadedState = null; // 2) does a row exist in the db for this entity? final boolean existsInDb = true; - session.getPersistenceContext().addEntity( + session.getPersistenceContextInternal().addEntity( target, Status.READ_ONLY, loadedState, diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java index dd80a81621..a2dc08254d 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java @@ -25,6 +25,7 @@ import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.internal.ForeignKeys; import org.hibernate.engine.spi.CollectionEntry; import org.hibernate.engine.spi.EntityEntry; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -162,7 +163,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers new LazyInitializationWork() { @Override public Boolean doWork() { - final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); + final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this ); if ( entry != null ) { final CollectionPersister persister = entry.getLoadedPersister(); @@ -253,7 +254,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers ( (Session) session ).beginTransaction(); } - session.getPersistenceContext().addUninitializedDetachedCollection( + session.getPersistenceContextInternal().addUninitializedDetachedCollection( session.getFactory().getCollectionPersister( getRole() ), this ); @@ -289,7 +290,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers final SessionFactoryImplementor sf = (SessionFactoryImplementor) SessionFactoryRegistry.INSTANCE.getSessionFactory( sessionFactoryUuid ); final SharedSessionContractImplementor session = (SharedSessionContractImplementor) sf.openSession(); - session.getPersistenceContext().setDefaultReadOnly( true ); + session.getPersistenceContextInternal().setDefaultReadOnly( true ); session.setFlushMode( FlushMode.MANUAL ); return session; } @@ -300,7 +301,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers new LazyInitializationWork() { @Override public Boolean doWork() { - final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); + final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this ); final CollectionPersister persister = entry.getLoadedPersister(); if ( persister.isExtraLazy() ) { if ( hasQueuedOperations() ) { @@ -328,7 +329,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers new LazyInitializationWork() { @Override public Boolean doWork() { - final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); + final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this ); final CollectionPersister persister = entry.getLoadedPersister(); if ( persister.isExtraLazy() ) { if ( hasQueuedOperations() ) { @@ -360,7 +361,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers @Override public Object doWork() { - final CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this ); + final CollectionEntry entry = session.getPersistenceContextInternal().getCollectionEntry( AbstractPersistentCollection.this ); final CollectionPersister persister = entry.getLoadedPersister(); isExtraLazy = persister.isExtraLazy(); if ( isExtraLazy ) { @@ -394,7 +395,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers protected boolean isConnectedToSession() { return session != null && session.isOpen() - && session.getPersistenceContext().containsCollection( this ); + && session.getPersistenceContextInternal().containsCollection( this ); } protected boolean isInitialized() { @@ -449,7 +450,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers */ @SuppressWarnings({"JavaDoc"}) protected boolean isInverseCollection() { - final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); + final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this ); return ce != null && ce.getLoadedPersister().isInverse(); } @@ -459,7 +460,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers */ @SuppressWarnings({"JavaDoc"}) protected boolean isInverseCollectionNoOrphanDelete() { - final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); + final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this ); return ce != null && ce.getLoadedPersister().isInverse() && @@ -472,7 +473,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers */ @SuppressWarnings({"JavaDoc"}) protected boolean isInverseOneToManyOrNoOrphanDelete() { - final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); + final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this ); return ce != null && ce.getLoadedPersister().isInverse() && ( ce.getLoadedPersister().isOneToMany() || !ce.getLoadedPersister().hasOrphanDelete() ); @@ -714,7 +715,7 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers sb.append( MessageHelper.collectionInfoString( roleCurrent, keyCurrent ) ); } else { - final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( this ); + final CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( this ); if ( ce != null ) { sb.append( MessageHelper.collectionInfoString( @@ -1249,9 +1250,10 @@ public abstract class AbstractPersistentCollection implements Serializable, Pers // collect EntityIdentifier(s) of the *current* elements - add them into a HashSet for fast access final java.util.Set currentIds = new HashSet(); final java.util.Set currentSaving = new IdentitySet(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); for ( Object current : currentElements ) { if ( current != null && ForeignKeys.isNotTransient( entityName, current, null, session ) ) { - final EntityEntry ee = session.getPersistenceContext().getEntry( current ); + final EntityEntry ee = persistenceContext.getEntry( current ); if ( ee != null && ee.getStatus() == Status.SAVING ) { currentSaving.add( current ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/OptimisticForceIncrementLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/OptimisticForceIncrementLockingStrategy.java index 61e4c4f3ee..4c9b487f92 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/OptimisticForceIncrementLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/OptimisticForceIncrementLockingStrategy.java @@ -48,7 +48,7 @@ public class OptimisticForceIncrementLockingStrategy implements LockingStrategy if ( !lockable.isVersioned() ) { throw new HibernateException( "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" ); } - final EntityEntry entry = session.getPersistenceContext().getEntry( object ); + final EntityEntry entry = session.getPersistenceContextInternal().getEntry( object ); // Register the EntityIncrementVersionProcess action to run just prior to transaction commit. ( (EventSource) session ).getActionQueue().registerProcess( new EntityIncrementVersionProcess( object, entry ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/OptimisticLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/OptimisticLockingStrategy.java index 262149c2aa..80e5d9bb1a 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/OptimisticLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/OptimisticLockingStrategy.java @@ -49,7 +49,7 @@ public class OptimisticLockingStrategy implements LockingStrategy { if ( !lockable.isVersioned() ) { throw new OptimisticLockException( object, "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" ); } - final EntityEntry entry = session.getPersistenceContext().getEntry( object ); + final EntityEntry entry = session.getPersistenceContextInternal().getEntry( object ); // Register the EntityVerifyVersionProcess action to run just prior to transaction commit. ( (EventSource) session ).getActionQueue().registerProcess( new EntityVerifyVersionProcess( object, entry ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticForceIncrementLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticForceIncrementLockingStrategy.java index b105eee303..7e81c5ac93 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticForceIncrementLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticForceIncrementLockingStrategy.java @@ -47,7 +47,7 @@ public class PessimisticForceIncrementLockingStrategy implements LockingStrategy if ( !lockable.isVersioned() ) { throw new HibernateException( "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" ); } - final EntityEntry entry = session.getPersistenceContext().getEntry( object ); + final EntityEntry entry = session.getPersistenceContextInternal().getEntry( object ); final EntityPersister persister = entry.getPersister(); final Object nextVersion = persister.forceVersionIncrement( entry.getId(), entry.getVersion(), session ); entry.forceLocked( object, nextVersion ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java index 714f2f932b..c5045b4f46 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java @@ -309,7 +309,7 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry { return !isExistsInDatabase(); } else { - return session.getPersistenceContext().getNullifiableEntityKeys().contains( getEntityKey() ); + return session.getPersistenceContextInternal().getNullifiableEntityKeys().contains( getEntityKey() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/BatchFetchQueueHelper.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/BatchFetchQueueHelper.java index 225bef5735..608cf22a6b 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/BatchFetchQueueHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/BatchFetchQueueHelper.java @@ -79,7 +79,7 @@ public class BatchFetchQueueHelper { EntityPersister persister, SharedSessionContractImplementor session) { final EntityKey entityKey = session.generateEntityKey( id, persister ); - final BatchFetchQueue batchFetchQueue = session.getPersistenceContext().getBatchFetchQueue(); + final BatchFetchQueue batchFetchQueue = session.getPersistenceContextInternal().getBatchFetchQueue(); batchFetchQueue.removeBatchLoadableEntityKey( entityKey ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java index 7d9d97ceca..eba00aebf3 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java @@ -18,6 +18,7 @@ import org.hibernate.engine.spi.CascadeStyle; import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.CollectionEntry; import org.hibernate.engine.spi.EntityEntry; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.Status; import org.hibernate.event.spi.EventSource; import org.hibernate.internal.CoreLogging; @@ -83,6 +84,7 @@ public final class Cascade { if ( traceEnabled ) { LOG.tracev( "Processing cascade {0} for: {1}", action, persister.getEntityName() ); } + final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal(); final Type[] types = persister.getPropertyTypes(); final String[] propertyNames = persister.getPropertyNames(); @@ -105,7 +107,7 @@ public final class Cascade { // If parent is a detached entity being merged, // then parent will not be in the PersistencContext // (so lazy attributes must not be initialized). - if ( eventSource.getPersistenceContext().getEntry( parent ) == null ) { + if ( persistenceContext.getEntry( parent ) == null ) { // parent was not in the PersistenceContext continue; } @@ -271,7 +273,8 @@ public final class Cascade { if ( style.hasOrphanDelete() && action.deleteOrphans() ) { // value is orphaned if loaded state for this property shows not null // because it is currently null. - final EntityEntry entry = eventSource.getPersistenceContext().getEntry( parent ); + final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal(); + final EntityEntry entry = persistenceContext.getEntry( parent ); if ( entry != null && entry.getStatus() != Status.SAVING ) { Object loadedValue; if ( componentPathStackDepth == 0 ) { @@ -299,15 +302,13 @@ public final class Cascade { // orphaned if the association was nulled (child == null) or receives a new value while the // entity is managed (without first nulling and manually flushing). if ( child == null || ( loadedValue != null && child != loadedValue ) ) { - EntityEntry valueEntry = eventSource - .getPersistenceContext().getEntry( - loadedValue ); + EntityEntry valueEntry = persistenceContext.getEntry( loadedValue ); if ( valueEntry == null && loadedValue instanceof HibernateProxy ) { // un-proxy and re-associate for cascade operation // useful for @OneToOne defined as FetchType.LAZY - loadedValue = eventSource.getPersistenceContext().unproxyAndReassociate( loadedValue ); - valueEntry = eventSource.getPersistenceContext().getEntry( loadedValue ); + loadedValue = persistenceContext.unproxyAndReassociate( loadedValue ); + valueEntry = persistenceContext.getEntry( loadedValue ); // HHH-11965 // Should the unwrapped proxy value be equal via reference to the entity's property value @@ -485,12 +486,13 @@ public final class Cascade { : null; if ( style.reallyDoCascade( action ) ) { //not really necessary, but good for consistency... - eventSource.getPersistenceContext().addChildParent( child, parent ); + final PersistenceContext persistenceContext = eventSource.getPersistenceContextInternal(); + persistenceContext.addChildParent( child, parent ); try { action.cascade( eventSource, child, entityName, anything, isCascadeDeleteEnabled ); } finally { - eventSource.getPersistenceContext().removeChildParent( child ); + persistenceContext.removeChildParent( child ); } } } @@ -570,7 +572,7 @@ public final class Cascade { //TODO: suck this logic into the collection! final Collection orphans; if ( pc.wasInitialized() ) { - final CollectionEntry ce = eventSource.getPersistenceContext().getCollectionEntry( pc ); + final CollectionEntry ce = eventSource.getPersistenceContextInternal().getCollectionEntry( pc ); orphans = ce==null ? java.util.Collections.EMPTY_LIST : ce.getOrphans( entityName, pc ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/Collections.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/Collections.java index f4b4a61a96..2683657b8e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/Collections.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/Collections.java @@ -53,7 +53,7 @@ public final class Collections { } private static void processDereferencedCollection(PersistentCollection coll, SessionImplementor session) { - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final CollectionEntry entry = persistenceContext.getCollectionEntry( coll ); final CollectionPersister loadedPersister = entry.getLoadedPersister(); @@ -111,7 +111,7 @@ public final class Collections { private static void processNeverReferencedCollection(PersistentCollection coll, SessionImplementor session) throws HibernateException { - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final CollectionEntry entry = persistenceContext.getCollectionEntry( coll ); if ( LOG.isDebugEnabled() ) { @@ -147,7 +147,8 @@ public final class Collections { Object entity, SessionImplementor session) { collection.setOwner( entity ); - final CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( collection ); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + final CollectionEntry ce = persistenceContext.getCollectionEntry( collection ); if ( ce == null ) { // refer to comment in StatefulPersistenceContext.addCollection() diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/ForeignKeys.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/ForeignKeys.java index 879533baff..860350e038 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/ForeignKeys.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/ForeignKeys.java @@ -160,7 +160,7 @@ public final class ForeignKeys { if ( isDelete && value == LazyPropertyInitializer.UNFETCHED_PROPERTY && type.isEntityType() && - !session.getPersistenceContext().getNullifiableEntityKeys().isEmpty() ) { + !session.getPersistenceContextInternal().getNullifiableEntityKeys().isEmpty() ) { // IMPLEMENTATION NOTE: If cascade-remove was mapped for the attribute, // then value should have been initialized previously, when the remove operation was // cascaded to the property (because CascadingAction.DELETE.performOnLazyProperty() @@ -225,7 +225,7 @@ public final class ForeignKeys { // id is not "unsaved" (that is, we rely on foreign keys to keep // database integrity) - final EntityEntry entityEntry = session.getPersistenceContext().getEntry( object ); + final EntityEntry entityEntry = session.getPersistenceContextInternal().getEntry( object ); if ( entityEntry == null ) { return isTransient( entityName, object, null, session ); } @@ -254,7 +254,7 @@ public final class ForeignKeys { return true; } - if ( session.getPersistenceContext().isEntryFor( entity ) ) { + if ( session.getPersistenceContextInternal().isEntryFor( entity ) ) { return true; } @@ -303,7 +303,7 @@ public final class ForeignKeys { } // hit the database, after checking the session cache for a snapshot - final Object[] snapshot = session.getPersistenceContext().getDatabaseSnapshot( + final Object[] snapshot = session.getPersistenceContextInternal().getDatabaseSnapshot( persister.getIdentifier( entity, session ), persister ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java index b70bd4d7a9..5afabbcfeb 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java @@ -1410,7 +1410,7 @@ public class StatefulPersistenceContext implements PersistenceContext { setEntityReadOnly( object, readOnly ); // PersistenceContext.proxyFor( entity ) returns entity if there is no proxy for that entity // so need to check the return value to be sure it is really a proxy - final Object maybeProxy = getSession().getPersistenceContext().proxyFor( object ); + final Object maybeProxy = getSession().getPersistenceContextInternal().proxyFor( object ); if ( maybeProxy instanceof HibernateProxy ) { setProxyReadOnly( (HibernateProxy) maybeProxy, readOnly ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java index 445bb95469..a396aba835 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java @@ -83,7 +83,7 @@ public final class TwoPhaseLoad { final LockMode lockMode, final SharedSessionContractImplementor session) { final Object version = Versioning.getVersion( values, persister ); - session.getPersistenceContext().addEntry( + session.getPersistenceContextInternal().addEntry( object, Status.LOADING, values, @@ -152,7 +152,7 @@ public final class TwoPhaseLoad { final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent, final Iterable preLoadEventListeners) { - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final EntityEntry entityEntry = persistenceContext.getEntry( entity ); if ( entityEntry == null ) { throw new AssertionFailure( "possible non-threadsafe access to the session" ); @@ -167,7 +167,7 @@ public final class TwoPhaseLoad { final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent, final Iterable preLoadEventListeners) throws HibernateException { - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final EntityPersister persister = entityEntry.getPersister(); final Serializable id = entityEntry.getId(); final Object[] hydratedState = entityEntry.getLoadedState(); @@ -264,7 +264,7 @@ public final class TwoPhaseLoad { // 2) Session#clear + some form of load // // we need to be careful not to clobber the lock here in the cache so that it can be rolled back if need be - if ( session.getPersistenceContext().wasInsertedDuringTransaction( persister, id ) ) { + if ( session.getPersistenceContextInternal().wasInsertedDuringTransaction( persister, id ) ) { cache.update( session, cacheKey, @@ -380,18 +380,17 @@ public final class TwoPhaseLoad { String entityName, String associationName, Type type) { - if ( type.isAssociationType() || type.isCollectionType() ) { + // Performance: check type.isCollectionType() first, as type.isAssociationType() is megamorphic + if ( type.isCollectionType() || type.isAssociationType() ) { Boolean overridingEager = isEagerFetchProfile( session, entityName, associationName ); - if ( LOG.isDebugEnabled() ) { - if ( overridingEager != null ) { - LOG.debugf( - "Overriding eager fetching using active fetch profile. EntityName: %s, associationName: %s, eager fetching: %s", - entityName, - associationName, - overridingEager - ); - } + if ( overridingEager != null ) { + LOG.debugf( + "Overriding eager fetching using active fetch profile. EntityName: %s, associationName: %s, eager fetching: %s", + entityName, + associationName, + overridingEager + ); } return overridingEager; @@ -438,7 +437,7 @@ public final class TwoPhaseLoad { if ( session.isEventSource() ) { final PersistenceContext persistenceContext - = session.getPersistenceContext(); + = session.getPersistenceContextInternal(); final EntityEntry entityEntry = persistenceContext.getEntry( entity ); postLoadEvent.setEntity( entity ).setId( entityEntry.getId() ).setPersister( entityEntry.getPersister() ); @@ -497,7 +496,7 @@ public final class TwoPhaseLoad { final EntityPersister persister, final LockMode lockMode, final SharedSessionContractImplementor session) { - session.getPersistenceContext().addEntity( + session.getPersistenceContextInternal().addEntity( object, Status.LOADING, null, @@ -527,7 +526,7 @@ public final class TwoPhaseLoad { final LockMode lockMode, final Object version, final SharedSessionContractImplementor session) { - session.getPersistenceContext().addEntity( + session.getPersistenceContextInternal().addEntity( object, Status.LOADING, null, diff --git a/hibernate-core/src/main/java/org/hibernate/engine/loading/internal/CollectionLoadContext.java b/hibernate-core/src/main/java/org/hibernate/engine/loading/internal/CollectionLoadContext.java index c76d6014d9..89e76820f7 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/loading/internal/CollectionLoadContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/loading/internal/CollectionLoadContext.java @@ -23,6 +23,7 @@ import org.hibernate.cache.spi.entry.CollectionCacheEntry; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.CollectionEntry; import org.hibernate.engine.spi.CollectionKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.Status; @@ -163,6 +164,7 @@ public class CollectionLoadContext { // the #endRead processing. List matches = null; final Iterator itr = localLoadingCollectionKeys.iterator(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); while ( itr.hasNext() ) { final CollectionKey collectionKey = (CollectionKey) itr.next(); final LoadingCollectionEntry lce = loadContexts.locateLoadingCollectionEntry( collectionKey ); @@ -175,7 +177,7 @@ public class CollectionLoadContext { } matches.add( lce ); if ( lce.getCollection().getOwner() == null ) { - session.getPersistenceContext().addUnownedCollection( + persistenceContext.addUnownedCollection( new CollectionKey( persister, lce.getKey() @@ -310,7 +312,8 @@ public class CollectionLoadContext { * @param persister The persister */ private void addCollectionToCache(LoadingCollectionEntry lce, CollectionPersister persister) { - final SharedSessionContractImplementor session = getLoadContext().getPersistenceContext().getSession(); + final PersistenceContext persistenceContext = getLoadContext().getPersistenceContext(); + final SharedSessionContractImplementor session = persistenceContext.getSession(); final SessionFactoryImplementor factory = session.getFactory(); if ( LOG.isDebugEnabled() ) { @@ -331,7 +334,7 @@ public class CollectionLoadContext { final Object version; if ( persister.isVersioned() ) { - Object collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( lce.getKey(), persister ); + Object collectionOwner = persistenceContext.getCollectionOwner( lce.getKey(), persister ); if ( collectionOwner == null ) { // generally speaking this would be caused by the collection key being defined by a property-ref, thus // the collection key and the owner key would not match up. In this case, try to use the key of the @@ -342,7 +345,7 @@ public class CollectionLoadContext { final Object linkedOwner = lce.getCollection().getOwner(); if ( linkedOwner != null ) { final Serializable ownerKey = persister.getOwnerEntityPersister().getIdentifier( linkedOwner, session ); - collectionOwner = getLoadContext().getPersistenceContext().getCollectionOwner( ownerKey, persister ); + collectionOwner = persistenceContext.getCollectionOwner( ownerKey, persister ); } } if ( collectionOwner == null ) { @@ -353,7 +356,7 @@ public class CollectionLoadContext { ); } } - version = getLoadContext().getPersistenceContext().getEntry( collectionOwner ).getVersion(); + version = persistenceContext.getEntry( collectionOwner ).getVersion(); } else { version = null; @@ -372,7 +375,7 @@ public class CollectionLoadContext { if ( persister.getElementType().isAssociationType() ) { for ( Serializable id : entry.getState() ) { EntityPersister entityPersister = ( (QueryableCollection) persister ).getElementPersister(); - if ( session.getPersistenceContext().wasInsertedDuringTransaction( entityPersister, id ) ) { + if ( persistenceContext.wasInsertedDuringTransaction( entityPersister, id ) ) { isPutFromLoad = false; break; } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadingActions.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadingActions.java index aa332bf96b..eef7e7b8cc 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadingActions.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/CascadingActions.java @@ -393,7 +393,7 @@ public class CascadingActions { } private boolean isInManagedState(Object child, EventSource session) { - EntityEntry entry = session.getPersistenceContext().getEntry( child ); + EntityEntry entry = session.getPersistenceContextInternal().getEntry( child ); return entry != null && ( entry.getStatus() == Status.MANAGED || diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java index f8f189cb7a..b113a0181a 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java @@ -204,7 +204,7 @@ public final class CollectionEntry implements Serializable { collection.setSnapshot(loadedKey, role, snapshot); if ( loadedPersister.getBatchSize() > 1 ) { ( (AbstractPersistentCollection) collection ).getSession() - .getPersistenceContext() + .getPersistenceContextInternal() .getBatchFetchQueue() .removeBatchLoadableCollection( this ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java index a942be7c1f..958ad8533e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java @@ -470,7 +470,7 @@ public final class QueryParameters { public boolean isReadOnly(SharedSessionContractImplementor session) { return isReadOnlyInitialized ? isReadOnly() - : session.getPersistenceContext().isDefaultReadOnly(); + : session.getPersistenceContextInternal().isDefaultReadOnly(); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java index 0d1e767286..fc2fdce73e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SessionDelegatorBaseImpl.java @@ -466,6 +466,11 @@ public class SessionDelegatorBaseImpl implements SessionImplementor { return delegate.getExceptionConverter(); } + @Override + public PersistenceContext getPersistenceContextInternal() { + return delegate.getPersistenceContextInternal(); + } + @Override public SessionEventListenerManager getEventListenerManager() { return delegate.getEventListenerManager(); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java index a39d51d58e..7458483ab9 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java @@ -91,7 +91,13 @@ public interface SharedSessionContractImplementor SessionEventListenerManager getEventListenerManager(); /** - * Get the persistence context for this session + * Get the persistence context for this session. + * See also {@link #getPersistenceContextInternal()} for + * an alternative. + * + * This method is not extremely fast: if you need to access + * the PersistenceContext multiple times, prefer keeping + * a reference to it over invoking this method multiple times. */ PersistenceContext getPersistenceContext(); @@ -504,4 +510,19 @@ public interface SharedSessionContractImplementor Class resultClass, Selection selection, HibernateEntityManagerImplementor.QueryOptions queryOptions); + + /** + * This is similar to {@link #getPersistenceContext()}, with + * two main differences: + * a) this version performs better as + * it allows for inlining and probably better prediction + * b) see SessionImpl{@link #getPersistenceContext()} : it + * does some checks on the current state of the Session. + * + * Choose wisely: performance is important, correctness comes first. + * + * @return the PersistenceContext associated to this session. + */ + PersistenceContext getPersistenceContextInternal(); + } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java index 6fd35ae0fb..fcbc02712e 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java @@ -19,6 +19,7 @@ import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.internal.Cascade; import org.hibernate.engine.internal.CascadePoint; import org.hibernate.engine.internal.Collections; +import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.spi.ActionQueue; import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.CascadingActions; @@ -77,7 +78,7 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi EventSource session = event.getSession(); - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); session.getInterceptor().preFlush( new LazyIterator( persistenceContext.getEntitiesByKey() ) ); prepareEntityFlushes( session, persistenceContext ); @@ -111,7 +112,7 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi return; } final EventSource session = event.getSession(); - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); LOG.debugf( "Flushed: %s insertions, %s updates, %s deletions to %s objects", session.getActionQueue().numberOfInsertions(), @@ -154,12 +155,13 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi private void cascadeOnFlush(EventSource session, EntityPersister persister, Object object, Object anything) throws HibernateException { - session.getPersistenceContext().incrementCascadeLevel(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + persistenceContext.incrementCascadeLevel(); try { Cascade.cascade( getCascadingAction(), CascadePoint.BEFORE_FLUSH, session, persister, object, anything ); } finally { - session.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); } } @@ -347,17 +349,20 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi // during-flush callbacks more leniency in regards to initializing proxies and // lazy collections during their processing. // For more information, see HHH-2763 + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator(); try { - session.getJdbcCoordinator().flushBeginning(); - session.getPersistenceContext().setFlushing( true ); + jdbcCoordinator.flushBeginning(); + persistenceContext.setFlushing( true ); // we need to lock the collection caches before executing entity inserts/updates in order to // account for bi-directional associations - session.getActionQueue().prepareActions(); - session.getActionQueue().executeActions(); + final ActionQueue actionQueue = session.getActionQueue(); + actionQueue.prepareActions(); + actionQueue.executeActions(); } finally { - session.getPersistenceContext().setFlushing( false ); - session.getJdbcCoordinator().flushEnding(); + persistenceContext.setFlushing( false ); + jdbcCoordinator.flushEnding(); } } @@ -375,7 +380,7 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi LOG.trace( "Post flush" ); - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); persistenceContext.getCollectionsByKey().clear(); // the database has changed now, so the subselect results need to be invalidated @@ -406,6 +411,6 @@ public abstract class AbstractFlushingEventListener implements JpaBootstrapSensi } protected void postPostFlush(SessionImplementor session) { - session.getInterceptor().postFlush( new LazyIterator( session.getPersistenceContext().getEntitiesByKey() ) ); + session.getInterceptor().postFlush( new LazyIterator( session.getPersistenceContextInternal().getEntitiesByKey() ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractReassociateEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractReassociateEventListener.java index f4527660f4..2bdc1cbcbb 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractReassociateEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractReassociateEventListener.java @@ -12,6 +12,7 @@ import org.hibernate.LockMode; import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.Status; import org.hibernate.event.spi.AbstractEvent; import org.hibernate.event.spi.EventSource; @@ -54,7 +55,8 @@ public abstract class AbstractReassociateEventListener implements Serializable { final EventSource source = event.getSession(); final EntityKey key = source.generateEntityKey( id, persister ); - source.getPersistenceContext().checkUniqueness( key, object ); + final PersistenceContext persistenceContext = source.getPersistenceContext(); + persistenceContext.checkUniqueness( key, object ); //get a snapshot Object[] values = persister.getPropertyValues( object ); @@ -67,7 +69,7 @@ public abstract class AbstractReassociateEventListener implements Serializable { ); Object version = Versioning.getVersion( values, persister ); - EntityEntry newEntry = source.getPersistenceContext().addEntity( + EntityEntry newEntry = persistenceContext.addEntity( object, ( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ), values, diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java index 290f5b4739..61b63ccddc 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java @@ -23,6 +23,7 @@ import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityEntryExtraState; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SelfDirtinessTracker; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.Status; @@ -174,10 +175,11 @@ public abstract class AbstractSaveEventListener final EntityKey key; if ( !useIdentityColumn ) { key = source.generateEntityKey( id, persister ); - Object old = source.getPersistenceContext().getEntity( key ); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + Object old = persistenceContext.getEntity( key ); if ( old != null ) { - if ( source.getPersistenceContext().getEntry( old ).getStatus() == Status.DELETED ) { - source.forceFlush( source.getPersistenceContext().getEntry( old ) ); + if ( persistenceContext.getEntry( old ).getStatus() == Status.DELETED ) { + source.forceFlush( persistenceContext.getEntry( old ) ); } else { throw new NonUniqueObjectException( id, persister.getEntityName() ); @@ -246,11 +248,12 @@ public abstract class AbstractSaveEventListener boolean inTrx = source.isTransactionInProgress(); boolean shouldDelayIdentityInserts = !inTrx && !requiresImmediateIdAccess; + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); // Put a placeholder in entries, so we don't recurse back and try to save() the // same object again. QUESTION: should this be done before onSave() is called? // likewise, should it be done before onUpdate()? - EntityEntry original = source.getPersistenceContext().addEntry( + EntityEntry original = persistenceContext.addEntry( entity, Status.SAVING, null, @@ -305,7 +308,7 @@ public abstract class AbstractSaveEventListener insert.handleNaturalIdPostSaveNotifications( id ); } - EntityEntry newEntry = source.getPersistenceContext().getEntry( entity ); + EntityEntry newEntry = persistenceContext.getEntry( entity ); if ( newEntry != original ) { EntityEntryExtraState extraState = newEntry.getExtraState( EntityEntryExtraState.class ); @@ -423,7 +426,8 @@ public abstract class AbstractSaveEventListener Object anything) { // cascade-save to many-to-one BEFORE the parent is saved - source.getPersistenceContext().incrementCascadeLevel(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + persistenceContext.incrementCascadeLevel(); try { Cascade.cascade( getCascadeAction(), @@ -435,7 +439,7 @@ public abstract class AbstractSaveEventListener ); } finally { - source.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); } } @@ -453,8 +457,9 @@ public abstract class AbstractSaveEventListener Object entity, Object anything) { + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); // cascade-save to collections AFTER the collection owner was saved - source.getPersistenceContext().incrementCascadeLevel(); + persistenceContext.incrementCascadeLevel(); try { Cascade.cascade( getCascadeAction(), @@ -466,7 +471,7 @@ public abstract class AbstractSaveEventListener ); } finally { - source.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultAutoFlushEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultAutoFlushEventListener.java index 34dcfbf9ce..1ec58e3366 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultAutoFlushEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultAutoFlushEventListener.java @@ -8,6 +8,7 @@ package org.hibernate.event.internal; import org.hibernate.FlushMode; import org.hibernate.HibernateException; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.event.spi.AutoFlushEvent; import org.hibernate.event.spi.AutoFlushEventListener; import org.hibernate.event.spi.EventSource; @@ -78,9 +79,10 @@ public class DefaultAutoFlushEventListener extends AbstractFlushingEventListener } private boolean flushMightBeNeeded(final EventSource source) { + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); return !source.getHibernateFlushMode().lessThan( FlushMode.AUTO ) && source.getDontFlushFromFind() == 0 - && ( source.getPersistenceContext().getNumberOfManagedEntities() > 0 || - source.getPersistenceContext().getCollectionEntries().size() > 0 ); + && ( persistenceContext.getNumberOfManagedEntities() > 0 || + persistenceContext.getCollectionEntries().size() > 0 ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java index f04b7504b0..c1616245bc 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java @@ -84,7 +84,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback final EventSource source = event.getSession(); - final PersistenceContext persistenceContext = source.getPersistenceContext(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); Object entity = persistenceContext.unproxyAndReassociate( event.getObject() ); EntityEntry entityEntry = persistenceContext.getEntry( entity ); @@ -255,7 +255,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback ); } - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final Type[] propTypes = persister.getPropertyTypes(); final Object version = entityEntry.getVersion(); @@ -359,7 +359,8 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback CacheMode cacheMode = session.getCacheMode(); session.setCacheMode( CacheMode.GET ); - session.getPersistenceContext().incrementCascadeLevel(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + persistenceContext.incrementCascadeLevel(); try { // cascade-delete to collections BEFORE the collection owner is deleted Cascade.cascade( @@ -372,7 +373,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback ); } finally { - session.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); session.setCacheMode( cacheMode ); } } @@ -385,7 +386,8 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback CacheMode cacheMode = session.getCacheMode(); session.setCacheMode( CacheMode.GET ); - session.getPersistenceContext().incrementCascadeLevel(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + persistenceContext.incrementCascadeLevel(); try { // cascade-delete to many-to-one AFTER the parent was deleted Cascade.cascade( @@ -398,7 +400,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback ); } finally { - session.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); session.setCacheMode( cacheMode ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java index 1abf516c46..b14df64aec 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultEvictEventListener.java @@ -50,7 +50,7 @@ public class DefaultEvictEventListener implements EvictEventListener { } final EventSource source = event.getSession(); - final PersistenceContext persistenceContext = source.getPersistenceContext(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); if ( object instanceof HibernateProxy ) { final LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer(); @@ -108,8 +108,9 @@ public class DefaultEvictEventListener implements EvictEventListener { LOG.tracev( "Evicting {0}", MessageHelper.infoString( persister ) ); } + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); if ( persister.hasNaturalIdentifier() ) { - session.getPersistenceContext().getNaturalIdHelper().handleEviction( + persistenceContext.getNaturalIdHelper().handleEviction( object, persister, key.getIdentifier() @@ -127,8 +128,8 @@ public class DefaultEvictEventListener implements EvictEventListener { // This is now handled by removeEntity() //session.getPersistenceContext().removeDatabaseSnapshot(key); - session.getPersistenceContext().removeEntity( key ); - session.getPersistenceContext().removeEntry( object ); + persistenceContext.removeEntity( key ); + persistenceContext.removeEntry( object ); Cascade.cascade( CascadingActions.EVICT, CascadePoint.AFTER_EVICT, session, persister, object ); } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java index 06ba4b1a3d..1e60d6a5d7 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java @@ -21,6 +21,7 @@ import org.hibernate.engine.internal.Nullability; import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SelfDirtinessTracker; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.Status; @@ -35,6 +36,7 @@ import org.hibernate.jpa.event.spi.CallbackRegistryConsumer; import org.hibernate.metadata.ClassMetadata; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; +import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.type.Type; /** @@ -97,9 +99,10 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener final Type[] propertyTypes = persister.getPropertyTypes(); final boolean[] propertyUpdateability = persister.getPropertyUpdateability(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final Object[] snapshot = loaded == null - ? session.getPersistenceContext().getNaturalIdSnapshot( entry.getId(), persister ) - : session.getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( loaded, persister ); + ? persistenceContext.getNaturalIdSnapshot( entry.getId(), persister ) + : persistenceContext.getNaturalIdHelper().extractNaturalIdValues( loaded, persister ); for ( int i = 0; i < naturalIdentifierPropertiesIndexes.length; i++ ) { final int naturalIdentifierPropertyIndex = naturalIdentifierPropertiesIndexes[i]; @@ -693,13 +696,15 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener } private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) { + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); if ( persister.isSelectBeforeUpdateRequired() ) { - Object[] snapshot = session.getPersistenceContext() + Object[] snapshot = persistenceContext .getDatabaseSnapshot( id, persister ); if ( snapshot == null ) { //do we even really need this? the update will fail anyway.... - if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { - session.getFactory().getStatistics() + final StatisticsImplementor statistics = session.getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() ) { + statistics .optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), id ); @@ -708,6 +713,6 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener } // TODO: optimize away this lookup for entities w/o unsaved-value="undefined" final EntityKey entityKey = session.generateEntityKey( id, persister ); - return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey ); + return persistenceContext.getCachedDatabaseSnapshot( entityKey ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEventListener.java index 7986d3deb4..fc8889d5d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEventListener.java @@ -11,6 +11,7 @@ import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.FlushEvent; import org.hibernate.event.spi.FlushEventListener; +import org.hibernate.stat.spi.StatisticsImplementor; /** * Defines the default flush event listeners used by hibernate for @@ -27,7 +28,7 @@ public class DefaultFlushEventListener extends AbstractFlushingEventListener imp */ public void onFlush(FlushEvent event) throws HibernateException { final EventSource source = event.getSession(); - final PersistenceContext persistenceContext = source.getPersistenceContext(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); if ( persistenceContext.getNumberOfManagedEntities() > 0 || persistenceContext.getCollectionEntries().size() > 0 ) { @@ -48,8 +49,9 @@ public class DefaultFlushEventListener extends AbstractFlushingEventListener imp postPostFlush( source ); - if ( source.getFactory().getStatistics().isStatisticsEnabled() ) { - source.getFactory().getStatistics().flush(); + final StatisticsImplementor statistics = source.getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() ) { + statistics.flush(); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultInitializeCollectionEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultInitializeCollectionEventListener.java index 2ae622a05d..a7ba1f0a2f 100755 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultInitializeCollectionEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultInitializeCollectionEventListener.java @@ -23,6 +23,7 @@ import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.pretty.MessageHelper; +import org.hibernate.stat.spi.StatisticsImplementor; /** * @author Gavin King @@ -37,7 +38,7 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle PersistentCollection collection = event.getCollection(); SessionImplementor source = event.getSession(); - CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection ); + CollectionEntry ce = source.getPersistenceContextInternal().getCollectionEntry( collection ); if ( ce == null ) { throw new HibernateException( "collection was evicted" ); } @@ -76,8 +77,9 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle LOG.trace( "Collection initialized" ); } - if ( source.getFactory().getStatistics().isStatisticsEnabled() ) { - source.getFactory().getStatistics().fetchCollection( + final StatisticsImplementor statistics = source.getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() ) { + statistics.fetchCollection( ce.getLoadedPersister().getRole() ); } @@ -119,15 +121,16 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle final Object ck = cacheAccessStrategy.generateCacheKey( id, persister, factory, source.getTenantIdentifier() ); final Object ce = CacheHelper.fromSharedCache( source, ck, persister.getCacheAccessStrategy() ); - if ( factory.getStatistics().isStatisticsEnabled() ) { + final StatisticsImplementor statistics = factory.getStatistics(); + if ( statistics.isStatisticsEnabled() ) { if ( ce == null ) { - factory.getStatistics().collectionCacheMiss( + statistics.collectionCacheMiss( persister.getNavigableRole(), cacheAccessStrategy.getRegion().getName() ); } else { - factory.getStatistics().collectionCacheHit( + statistics.collectionCacheHit( persister.getNavigableRole(), cacheAccessStrategy.getRegion().getName() ); @@ -143,7 +146,7 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle factory ); - final PersistenceContext persistenceContext = source.getPersistenceContext(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); cacheEntry.assemble( collection, persister, persistenceContext.getCollectionOwner( id, persister ) ); persistenceContext.getCollectionEntry( collection ).postInitialize( collection ); // addInitializedCollection(collection, persister, id); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java index 126c7d684e..a0a1287b89 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java @@ -21,6 +21,7 @@ import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.Status; +import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.LoadEvent; import org.hibernate.event.spi.LoadEventListener; import org.hibernate.internal.CoreLogging; @@ -30,6 +31,7 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.pretty.MessageHelper; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; +import org.hibernate.tuple.entity.EntityMetamodel; import org.hibernate.type.EmbeddedComponentType; import org.hibernate.type.EntityType; import org.hibernate.type.Type; @@ -180,18 +182,19 @@ public class DefaultLoadEventListener implements LoadEventListener { final EntityKey keyToLoad, final LoadEventListener.LoadType options) { + final EventSource session = event.getSession(); if ( event.getInstanceToLoad() != null ) { - if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) { + if ( session.getPersistenceContextInternal().getEntry( event.getInstanceToLoad() ) != null ) { throw new PersistentObjectException( "attempted to load into an instance that was already associated with the session: " + MessageHelper.infoString( persister, event.getEntityId(), - event.getSession().getFactory() + session.getFactory() ) ); } - persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession() ); + persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), session); } final Object entity = doLoad( event, persister, keyToLoad, options ); @@ -199,7 +202,7 @@ public class DefaultLoadEventListener implements LoadEventListener { boolean isOptionalInstance = event.getInstanceToLoad() != null; if ( entity == null && ( !options.isAllowNulls() || isOptionalInstance ) ) { - event.getSession() + session .getFactory() .getEntityNotFoundDelegate() .handleEntityNotFound( event.getEntityClassName(), event.getEntityId() ); @@ -235,21 +238,22 @@ public class DefaultLoadEventListener implements LoadEventListener { ); } - final PersistenceContext persistenceContext = event.getSession().getPersistenceContext(); + final PersistenceContext persistenceContext = event.getSession().getPersistenceContextInternal(); final boolean allowBytecodeProxy = event.getSession() .getFactory() .getSessionFactoryOptions() .isEnhancementAsProxyEnabled(); - final boolean entityHasHibernateProxyFactory = persister.getEntityMetamodel() + final EntityMetamodel entityMetamodel = persister.getEntityMetamodel(); + final boolean entityHasHibernateProxyFactory = entityMetamodel .getTuplizer() .getProxyFactory() != null; // Check for the case where we can use the entity itself as a proxy if ( options.isAllowProxyCreation() && allowBytecodeProxy - && persister.getEntityMetamodel().getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) { + && entityMetamodel.getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() ) { // if there is already a managed entity instance associated with the PC, return it final Object managed = persistenceContext.getEntity( keyToLoad ); if ( managed != null ) { @@ -282,7 +286,7 @@ public class DefaultLoadEventListener implements LoadEventListener { } // specialized handling for entities with subclasses with a HibernateProxy factory - if ( persister.getEntityMetamodel().hasSubclasses() ) { + if ( entityMetamodel.hasSubclasses() ) { // entities with subclasses that define a ProxyFactory can create // a HibernateProxy so long as NO_PROXY was not specified. if ( event.getShouldUnwrapProxy() != null && event.getShouldUnwrapProxy() ) { @@ -460,7 +464,7 @@ public class DefaultLoadEventListener implements LoadEventListener { } } - return event.getSession().getPersistenceContext().proxyFor( persister, keyToLoad, entity ); + return event.getSession().getPersistenceContextInternal().proxyFor( persister, keyToLoad, entity ); } @@ -483,10 +487,11 @@ public class DefaultLoadEventListener implements LoadEventListener { final EntityKey keyToLoad, final LoadEventListener.LoadType options) { + final EventSource session = event.getSession(); if ( LOG.isTraceEnabled() ) { LOG.tracev( "Attempting to resolve: {0}", - MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() ) + MessageHelper.infoString( persister, event.getEntityId(), session.getFactory() ) ); } @@ -506,7 +511,7 @@ public class DefaultLoadEventListener implements LoadEventListener { if ( LOG.isTraceEnabled() ) { LOG.tracev( "Resolved object in second-level cache: {0}", - MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() ) + MessageHelper.infoString( persister, event.getEntityId(), session.getFactory() ) ); } } @@ -514,17 +519,18 @@ public class DefaultLoadEventListener implements LoadEventListener { if ( LOG.isTraceEnabled() ) { LOG.tracev( "Object not resolved in any cache: {0}", - MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() ) + MessageHelper.infoString( persister, event.getEntityId(), session.getFactory() ) ); } entity = loadFromDatasource( event, persister ); } if ( entity != null && persister.hasNaturalIdentifier() ) { - event.getSession().getPersistenceContext().getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad( + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + persistenceContext.getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad( persister, event.getEntityId(), - event.getSession().getPersistenceContext().getNaturalIdHelper().extractNaturalIdValues( + persistenceContext.getNaturalIdHelper().extractNaturalIdValues( entity, persister ) diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLockEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLockEventListener.java index d6ee7a0a79..703b8e1553 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLockEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLockEventListener.java @@ -16,6 +16,7 @@ import org.hibernate.engine.internal.CascadePoint; import org.hibernate.engine.internal.ForeignKeys; import org.hibernate.engine.spi.CascadingActions; import org.hibernate.engine.spi.EntityEntry; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.LockEvent; @@ -59,12 +60,12 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i } SessionImplementor source = event.getSession(); - - Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() ); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + Object entity = persistenceContext.unproxyAndReassociate( event.getObject() ); //TODO: if object was an uninitialized proxy, this is inefficient, // resulting in two SQL selects - EntityEntry entry = source.getPersistenceContext().getEntry(entity); + EntityEntry entry = persistenceContext.getEntry(entity); if (entry==null) { final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity ); final Serializable id = persister.getIdentifier( entity, source ); @@ -84,7 +85,8 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i private void cascadeOnLock(LockEvent event, EntityPersister persister, Object entity) { EventSource source = event.getSession(); - source.getPersistenceContext().incrementCascadeLevel(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + persistenceContext.incrementCascadeLevel(); try { Cascade.cascade( CascadingActions.LOCK, @@ -96,7 +98,7 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i ); } finally { - source.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java index d26353eba7..0b58ac9136 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java @@ -21,6 +21,7 @@ import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.CascadingActions; import org.hibernate.engine.spi.EntityEntry; 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.SelfDirtinessTracker; @@ -141,14 +142,15 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme // Check the persistence context for an entry relating to this // entity to be merged... - EntityEntry entry = source.getPersistenceContext().getEntry( entity ); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + EntityEntry entry = persistenceContext.getEntry( entity ); if ( entry == null ) { EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity ); Serializable id = persister.getIdentifier( entity, source ); if ( id != null ) { final EntityKey key = source.generateEntityKey( id, persister ); - final Object managedEntity = source.getPersistenceContext().getEntity( key ); - entry = source.getPersistenceContext().getEntry( managedEntity ); + final Object managedEntity = persistenceContext.getEntity( key ); + entry = persistenceContext.getEntry( managedEntity ); if ( entry != null ) { // we have specialized case of a detached entity from the // perspective of the merge operation. Specifically, we @@ -356,7 +358,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme EntityPersister persister, EventSource source) { if ( incoming instanceof HibernateProxy ) { - return source.getPersistenceContext().unproxy( managed ); + return source.getPersistenceContextInternal().unproxy( managed ); } if ( incoming instanceof PersistentAttributeInterceptable @@ -424,13 +426,14 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme } private boolean existsInDatabase(Object entity, EventSource source, EntityPersister persister) { - EntityEntry entry = source.getPersistenceContext().getEntry( entity ); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + EntityEntry entry = persistenceContext.getEntry( entity ); if ( entry == null ) { Serializable id = persister.getIdentifier( entity, source ); if ( id != null ) { final EntityKey key = source.generateEntityKey( id, persister ); - final Object managedEntity = source.getPersistenceContext().getEntity( key ); - entry = source.getPersistenceContext().getEntry( managedEntity ); + final Object managedEntity = persistenceContext.getEntity( key ); + entry = persistenceContext.getEntry( managedEntity ); } } @@ -508,7 +511,8 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme final Object entity, final Map copyCache ) { - source.getPersistenceContext().incrementCascadeLevel(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + persistenceContext.incrementCascadeLevel(); try { Cascade.cascade( getCascadeAction(), @@ -520,7 +524,7 @@ public class DefaultMergeEventListener extends AbstractSaveEventListener impleme ); } finally { - source.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPersistEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPersistEventListener.java index fedbc270fc..f1a2c01d7d 100755 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPersistEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPersistEventListener.java @@ -98,7 +98,7 @@ public class DefaultPersistEventListener event.setEntityName( entityName ); } - final EntityEntry entityEntry = source.getPersistenceContext().getEntry( entity ); + final EntityEntry entityEntry = source.getPersistenceContextInternal().getEntry( entity ); EntityState entityState = getEntityState( entity, entityName, entityEntry, source ); if ( entityState == EntityState.DETACHED ) { // JPA 2, in its version of a "foreign generated", allows the id attribute value @@ -160,7 +160,7 @@ public class DefaultPersistEventListener //TODO: check that entry.getIdentifier().equals(requestedId) - final Object entity = source.getPersistenceContext().unproxy( event.getObject() ); + final Object entity = source.getPersistenceContextInternal().unproxy( event.getObject() ); final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity ); if ( createCache.put( entity, entity ) == null ) { @@ -186,7 +186,7 @@ public class DefaultPersistEventListener LOG.trace( "Saving transient instance" ); final EventSource source = event.getSession(); - final Object entity = source.getPersistenceContext().unproxy( event.getObject() ); + final Object entity = source.getPersistenceContextInternal().unproxy( event.getObject() ); if ( createCache.put( entity, entity ) == null ) { saveWithGeneratedId( entity, event.getEntityName(), createCache, source, false ); @@ -197,7 +197,7 @@ public class DefaultPersistEventListener private void entityIsDeleted(PersistEvent event, Map createCache) { final EventSource source = event.getSession(); - final Object entity = source.getPersistenceContext().unproxy( event.getObject() ); + final Object entity = source.getPersistenceContextInternal().unproxy( event.getObject() ); final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity ); if ( LOG.isTraceEnabled() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPostLoadEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPostLoadEventListener.java index 5385cf13d0..df75a34013 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPostLoadEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPostLoadEventListener.java @@ -12,6 +12,7 @@ import org.hibernate.action.internal.EntityIncrementVersionProcess; import org.hibernate.action.internal.EntityVerifyVersionProcess; import org.hibernate.classic.Lifecycle; import org.hibernate.engine.spi.EntityEntry; +import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.PostLoadEvent; import org.hibernate.event.spi.PostLoadEventListener; import org.hibernate.jpa.event.spi.CallbackRegistry; @@ -41,7 +42,8 @@ public class DefaultPostLoadEventListener implements PostLoadEventListener, Call callbackRegistry.postLoad( entity ); - final EntityEntry entry = event.getSession().getPersistenceContext().getEntry( entity ); + final EventSource session = event.getSession(); + final EntityEntry entry = session.getPersistenceContextInternal().getEntry( entity ); if ( entry == null ) { throw new AssertionFailure( "possible non-threadsafe access to the session" ); } @@ -52,22 +54,22 @@ public class DefaultPostLoadEventListener implements PostLoadEventListener, Call final Object nextVersion = persister.forceVersionIncrement( entry.getId(), entry.getVersion(), - event.getSession() + session ); entry.forceLocked( entity, nextVersion ); } else if ( LockMode.OPTIMISTIC_FORCE_INCREMENT.equals( lockMode ) ) { final EntityIncrementVersionProcess incrementVersion = new EntityIncrementVersionProcess( entity, entry ); - event.getSession().getActionQueue().registerProcess( incrementVersion ); + session.getActionQueue().registerProcess( incrementVersion ); } else if ( LockMode.OPTIMISTIC.equals( lockMode ) ) { final EntityVerifyVersionProcess verifyVersion = new EntityVerifyVersionProcess( entity, entry ); - event.getSession().getActionQueue().registerProcess( verifyVersion ); + session.getActionQueue().registerProcess( verifyVersion ); } if ( event.getPersister().implementsLifecycle() ) { //log.debug( "calling onLoad()" ); - ( (Lifecycle) event.getEntity() ).onLoad( event.getSession(), event.getId() ); + ( (Lifecycle) event.getEntity() ).onLoad( session, event.getId() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java index c3588f2bd5..0c0f2624fb 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultRefreshEventListener.java @@ -23,6 +23,7 @@ import org.hibernate.engine.internal.CascadePoint; import org.hibernate.engine.spi.CascadingActions; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.RefreshEvent; import org.hibernate.event.spi.RefreshEventListener; @@ -63,21 +64,22 @@ public class DefaultRefreshEventListener implements RefreshEventListener { else { isTransient = !source.contains( event.getObject() ); } - if ( source.getPersistenceContext().reassociateIfUninitializedProxy( event.getObject() ) ) { + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + if ( persistenceContext.reassociateIfUninitializedProxy( event.getObject() ) ) { if ( isTransient ) { source.setReadOnly( event.getObject(), source.isDefaultReadOnly() ); } return; } - final Object object = source.getPersistenceContext().unproxyAndReassociate( event.getObject() ); + final Object object = persistenceContext.unproxyAndReassociate( event.getObject() ); if ( refreshedAlready.containsKey( object ) ) { LOG.trace( "Already refreshed" ); return; } - final EntityEntry e = source.getPersistenceContext().getEntry( object ); + final EntityEntry e = persistenceContext.getEntry( object ); final EntityPersister persister; final Serializable id; @@ -97,7 +99,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener { ); } final EntityKey key = source.generateEntityKey( id, persister ); - if ( source.getPersistenceContext().getEntry( key ) != null ) { + if ( persistenceContext.getEntry( key ) != null ) { throw new PersistentObjectException( "attempted to refresh transient instance when persistent instance was already associated with the Session: " + MessageHelper.infoString( persister, id, source.getFactory() ) @@ -138,7 +140,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener { if ( e != null ) { final EntityKey key = source.generateEntityKey( id, persister ); - source.getPersistenceContext().removeEntity( key ); + persistenceContext.removeEntity( key ); if ( persister.hasCollections() ) { new EvictVisitor( source, object ).process( object, persister ); } @@ -212,7 +214,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener { if ( postRefreshLockMode != null ) { // if we get here, there was a previous entry and we need to re-set its lock-mode // - however, the refresh operation actually creates a new entry, so get it - source.getPersistenceContext().getEntry( result ).setLockMode( postRefreshLockMode ); + persistenceContext.getEntry( result ).setLockMode( postRefreshLockMode ); } // Keep the same read-only/modifiable setting for the entity that it had before refreshing; diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java index 307b2e6924..c7c65da7c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java @@ -17,6 +17,7 @@ import org.hibernate.engine.internal.CascadePoint; import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.CascadingActions; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.Status; import org.hibernate.event.spi.EventSource; @@ -46,14 +47,15 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp */ public void onReplicate(ReplicateEvent event) { final EventSource source = event.getSession(); - if ( source.getPersistenceContext().reassociateIfUninitializedProxy( event.getObject() ) ) { + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + if ( persistenceContext.reassociateIfUninitializedProxy( event.getObject() ) ) { LOG.trace( "Uninitialized proxy passed to replicate()" ); return; } - Object entity = source.getPersistenceContext().unproxyAndReassociate( event.getObject() ); + Object entity = persistenceContext.unproxyAndReassociate( event.getObject() ); - if ( source.getPersistenceContext().isEntryFor( entity ) ) { + if ( persistenceContext.isEntryFor( entity ) ) { LOG.trace( "Ignoring persistent instance passed to replicate()" ); //hum ... should we cascade anyway? throw an exception? fine like it is? return; @@ -181,7 +183,7 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp new OnReplicateVisitor( source, id, entity, true ).process( entity, persister ); - source.getPersistenceContext().addEntity( + source.getPersistenceContextInternal().addEntity( entity, ( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ), null, @@ -201,7 +203,8 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp EntityPersister persister, ReplicationMode replicationMode, EventSource source) { - source.getPersistenceContext().incrementCascadeLevel(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + persistenceContext.incrementCascadeLevel(); try { Cascade.cascade( CascadingActions.REPLICATE, @@ -213,7 +216,7 @@ public class DefaultReplicateEventListener extends AbstractSaveEventListener imp ); } finally { - source.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultResolveNaturalIdEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultResolveNaturalIdEventListener.java index 01e46f3501..4767a2ea11 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultResolveNaturalIdEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultResolveNaturalIdEventListener.java @@ -11,7 +11,9 @@ import java.util.concurrent.TimeUnit; import org.hibernate.HibernateException; import org.hibernate.cache.spi.access.NaturalIdDataAccess; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.ResolveNaturalIdEvent; import org.hibernate.event.spi.ResolveNaturalIdEventListener; import org.hibernate.internal.CoreLogging; @@ -93,7 +95,7 @@ public class DefaultResolveNaturalIdEventListener * @return The entity from the cache, or null. */ protected Serializable resolveFromCache(final ResolveNaturalIdEvent event) { - return event.getSession().getPersistenceContext().getNaturalIdHelper().findCachedNaturalIdResolution( + return event.getSession().getPersistenceContextInternal().getNaturalIdHelper().findCachedNaturalIdResolution( event.getEntityPersister(), event.getOrderedNaturalIdValues() ); @@ -108,7 +110,8 @@ public class DefaultResolveNaturalIdEventListener * @return The object loaded from the datasource, or null if not found. */ protected Serializable loadFromDatasource(final ResolveNaturalIdEvent event) { - final SessionFactoryImplementor factory = event.getSession().getFactory(); + final EventSource session = event.getSession(); + final SessionFactoryImplementor factory = session.getFactory(); final boolean stats = factory.getStatistics().isStatisticsEnabled(); long startTime = 0; if ( stats ) { @@ -118,7 +121,7 @@ public class DefaultResolveNaturalIdEventListener final Serializable pk = event.getEntityPersister().loadEntityIdByNaturalId( event.getOrderedNaturalIdValues(), event.getLockOptions(), - event.getSession() + session ); if ( stats ) { @@ -132,7 +135,8 @@ public class DefaultResolveNaturalIdEventListener //PK can be null if the entity doesn't exist if (pk != null) { - event.getSession().getPersistenceContext().getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad( + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + persistenceContext.getNaturalIdHelper().cacheNaturalIdCrossReferenceFromLoad( event.getEntityPersister(), pk, event.getOrderedNaturalIdValues() diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultSaveEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultSaveEventListener.java index 9281c84b87..35c61b0846 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultSaveEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultSaveEventListener.java @@ -24,7 +24,7 @@ public class DefaultSaveEventListener extends DefaultSaveOrUpdateEventListener { protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) { // this implementation is supposed to tolerate incorrect unsaved-value // mappings, for the purpose of backward-compatibility - EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() ); + EntityEntry entry = event.getSession().getPersistenceContextInternal().getEntry( event.getEntity() ); if ( entry!=null && entry.getStatus() != Status.DELETED ) { return entityIsPersistent(event); } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultSaveOrUpdateEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultSaveOrUpdateEventListener.java index 3704b56afd..c853676843 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultSaveOrUpdateEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultSaveOrUpdateEventListener.java @@ -20,6 +20,7 @@ import org.hibernate.engine.spi.CascadingAction; import org.hibernate.engine.spi.CascadingActions; import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.Status; @@ -66,9 +67,10 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener } else { //initialize properties of the event: - final Object entity = source.getPersistenceContext().unproxyAndReassociate( object ); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + final Object entity = persistenceContext.unproxyAndReassociate( object ); event.setEntity( entity ); - event.setEntry( source.getPersistenceContext().getEntry( entity ) ); + event.setEntry( persistenceContext.getEntry( entity ) ); //return the id in the event object event.setResultId( performSaveOrUpdate( event ) ); } @@ -76,7 +78,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener } protected boolean reassociateIfUninitializedProxy(Object object, SessionImplementor source) { - return source.getPersistenceContext().reassociateIfUninitializedProxy( object ); + return source.getPersistenceContextInternal().reassociateIfUninitializedProxy( object ); } protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) { @@ -175,7 +177,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener Serializable id = saveWithGeneratedOrRequestedId( event ); - source.getPersistenceContext().reassociateProxy( event.getObject(), id ); + source.getPersistenceContextInternal().reassociateProxy( event.getObject(), id ); return id; } @@ -208,18 +210,19 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener LOG.trace( "Updating detached instance" ); - if ( event.getSession().getPersistenceContext().isEntryFor( event.getEntity() ) ) { + final EventSource session = event.getSession(); + if ( session.getPersistenceContextInternal().isEntryFor( event.getEntity() ) ) { //TODO: assertion only, could be optimized away throw new AssertionFailure( "entity was persistent" ); } Object entity = event.getEntity(); - EntityPersister persister = event.getSession().getEntityPersister( event.getEntityName(), entity ); + EntityPersister persister = session.getEntityPersister( event.getEntityName(), entity ); event.setRequestedId( getUpdateId( - entity, persister, event.getRequestedId(), event.getSession() + entity, persister, event.getRequestedId(), session ) ); @@ -279,7 +282,8 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener final EventSource source = event.getSession(); final EntityKey key = source.generateEntityKey( event.getRequestedId(), persister ); - source.getPersistenceContext().checkUniqueness( key, entity ); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + persistenceContext.checkUniqueness( key, entity ); if ( invokeUpdateLifecycle( entity, persister, source ) ) { reassociate( event, event.getObject(), event.getRequestedId(), persister ); @@ -302,7 +306,7 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener entry.getState(); //TODO: half-assemble this stuff }*/ - source.getPersistenceContext().addEntity( + persistenceContext.addEntity( entity, ( persister.isMutable() ? Status.MANAGED : Status.READ_ONLY ), null, // cachedState, @@ -350,12 +354,13 @@ public class DefaultSaveOrUpdateEventListener extends AbstractSaveEventListener */ private void cascadeOnUpdate(SaveOrUpdateEvent event, EntityPersister persister, Object entity) { final EventSource source = event.getSession(); - source.getPersistenceContext().incrementCascadeLevel(); + final PersistenceContext persistenceContext = source.getPersistenceContextInternal(); + persistenceContext.incrementCascadeLevel(); try { Cascade.cascade( CascadingActions.SAVE_UPDATE, CascadePoint.AFTER_UPDATE, source, persister, entity ); } finally { - source.getPersistenceContext().decrementCascadeLevel(); + persistenceContext.decrementCascadeLevel(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultUpdateEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultUpdateEventListener.java index a561a4ebd9..30165830fd 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultUpdateEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultUpdateEventListener.java @@ -25,7 +25,7 @@ public class DefaultUpdateEventListener extends DefaultSaveOrUpdateEventListener protected Serializable performSaveOrUpdate(SaveOrUpdateEvent event) { // this implementation is supposed to tolerate incorrect unsaved-value // mappings, for the purpose of backward-compatibility - EntityEntry entry = event.getSession().getPersistenceContext().getEntry( event.getEntity() ); + EntityEntry entry = event.getSession().getPersistenceContextInternal().getEntry( event.getEntity() ); if ( entry!=null ) { if ( entry.getStatus()== Status.DELETED ) { throw new ObjectDeletedException( "deleted instance passed to update()", null, event.getEntityName() ); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DirtyCollectionSearchVisitor.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DirtyCollectionSearchVisitor.java index 2a31ad70f5..1fce73d5fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DirtyCollectionSearchVisitor.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DirtyCollectionSearchVisitor.java @@ -39,7 +39,7 @@ public class DirtyCollectionSearchVisitor extends AbstractVisitor { final SessionImplementor session = getSession(); final PersistentCollection persistentCollection; if ( type.isArrayType() ) { - persistentCollection = session.getPersistenceContext().getCollectionHolder( collection ); + persistentCollection = session.getPersistenceContextInternal().getCollectionHolder( collection ); // if no array holder we found an unwrappered array (this can't occur, // because we now always call wrap() before getting to here) // return (ah==null) ? true : searchForDirtyCollections(ah, type); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/EvictVisitor.java b/hibernate-core/src/main/java/org/hibernate/event/internal/EvictVisitor.java index d440adab6b..d47d5498e6 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/EvictVisitor.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/EvictVisitor.java @@ -11,6 +11,7 @@ import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.CollectionEntry; import org.hibernate.engine.spi.CollectionKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.event.spi.EventSource; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; @@ -45,26 +46,28 @@ public class EvictVisitor extends AbstractVisitor { public void evictCollection(Object value, CollectionType type) { final PersistentCollection collection; + final EventSource session = getSession(); if ( type.hasHolder() ) { - collection = getSession().getPersistenceContext().removeCollectionHolder(value); + collection = session.getPersistenceContextInternal().removeCollectionHolder(value); } else if ( value instanceof PersistentCollection ) { collection = (PersistentCollection) value; } else if ( value == LazyPropertyInitializer.UNFETCHED_PROPERTY ) { - collection = (PersistentCollection) type.resolve( value, getSession(), this.owner ); + collection = (PersistentCollection) type.resolve( value, session, this.owner ); } else { return; //EARLY EXIT! } - if ( collection != null && collection.unsetSession( getSession() ) ) { + if ( collection != null && collection.unsetSession(session) ) { evictCollection(collection); } } private void evictCollection(PersistentCollection collection) { - CollectionEntry ce = (CollectionEntry) getSession().getPersistenceContext().getCollectionEntries().remove(collection); + final PersistenceContext persistenceContext = getSession().getPersistenceContextInternal(); + CollectionEntry ce = (CollectionEntry) persistenceContext.getCollectionEntries().remove(collection); if ( LOG.isDebugEnabled() ) { LOG.debugf( "Evicting collection: %s", @@ -74,11 +77,11 @@ public class EvictVisitor extends AbstractVisitor { getSession() ) ); } if (ce.getLoadedPersister() != null && ce.getLoadedPersister().getBatchSize() > 1) { - getSession().getPersistenceContext().getBatchFetchQueue().removeBatchLoadableCollection(ce); + persistenceContext.getBatchFetchQueue().removeBatchLoadableCollection(ce); } if ( ce.getLoadedPersister() != null && ce.getLoadedKey() != null ) { //TODO: is this 100% correct? - getSession().getPersistenceContext().getCollectionsByKey().remove( + persistenceContext.getCollectionsByKey().remove( new CollectionKey( ce.getLoadedPersister(), ce.getLoadedKey() ) ); } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/FlushVisitor.java b/hibernate-core/src/main/java/org/hibernate/event/internal/FlushVisitor.java index c5cb4caada..a3d8987182 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/FlushVisitor.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/FlushVisitor.java @@ -36,17 +36,18 @@ public class FlushVisitor extends AbstractVisitor { if ( collection != null ) { final PersistentCollection coll; + final EventSource session = getSession(); if ( type.hasHolder() ) { - coll = getSession().getPersistenceContext().getCollectionHolder(collection); + coll = session.getPersistenceContextInternal().getCollectionHolder(collection); } else if ( collection == LazyPropertyInitializer.UNFETCHED_PROPERTY ) { - coll = (PersistentCollection) type.resolve( collection, getSession(), owner ); + coll = (PersistentCollection) type.resolve( collection, session, owner ); } else { coll = (PersistentCollection) collection; } - Collections.processReachableCollection( coll, type, owner, getSession() ); + Collections.processReachableCollection( coll, type, owner, session); } return null; diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/MergeContext.java b/hibernate-core/src/main/java/org/hibernate/event/internal/MergeContext.java index a63cb7807f..6472418984 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/MergeContext.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/MergeContext.java @@ -374,7 +374,7 @@ class MergeContext implements Map { } private String printEntity(Object entity) { - if ( session.getPersistenceContext().getEntry( entity ) != null ) { + if ( session.getPersistenceContextInternal().getEntry( entity ) != null ) { return MessageHelper.infoString( session.getEntityName( entity ), session.getIdentifier( entity ) ); } // Entity was not found in current persistence context. Use Object#toString() method. diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/OnReplicateVisitor.java b/hibernate-core/src/main/java/org/hibernate/event/internal/OnReplicateVisitor.java index 5b3cdb78fa..281ba1a3f8 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/OnReplicateVisitor.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/OnReplicateVisitor.java @@ -51,7 +51,7 @@ public class OnReplicateVisitor extends ReattachVisitor { final PersistentCollection wrapper = (PersistentCollection) collection; wrapper.setCurrentSession( (SessionImplementor) session ); if ( wrapper.wasInitialized() ) { - session.getPersistenceContext().addNewCollection( persister, wrapper ); + session.getPersistenceContextInternal().addNewCollection( persister, wrapper ); } else { reattachCollection( wrapper, type ); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/PostUpdateEventListenerStandardImpl.java b/hibernate-core/src/main/java/org/hibernate/event/internal/PostUpdateEventListenerStandardImpl.java index 4e68dd10d9..bcf5b089c7 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/PostUpdateEventListenerStandardImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/PostUpdateEventListenerStandardImpl.java @@ -35,7 +35,7 @@ public class PostUpdateEventListenerStandardImpl implements PostUpdateEventListe } private void handlePostUpdate(Object entity, EventSource source) { - EntityEntry entry = source.getPersistenceContext().getEntry( entity ); + EntityEntry entry = source.getPersistenceContextInternal().getEntry( entity ); // mimic the preUpdate filter if ( Status.DELETED != entry.getStatus()) { callbackRegistry.postUpdate(entity); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/ProxyVisitor.java b/hibernate-core/src/main/java/org/hibernate/event/internal/ProxyVisitor.java index ae96fda7a4..e507baf21f 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/ProxyVisitor.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/ProxyVisitor.java @@ -64,19 +64,20 @@ public abstract class ProxyVisitor extends AbstractVisitor { */ protected void reattachCollection(PersistentCollection collection, CollectionType type) throws HibernateException { + final EventSource session = getSession(); if ( collection.wasInitialized() ) { - CollectionPersister collectionPersister = getSession().getFactory() + CollectionPersister collectionPersister = session.getFactory() .getCollectionPersister( type.getRole() ); - getSession().getPersistenceContext() + session.getPersistenceContext() .addInitializedDetachedCollection( collectionPersister, collection ); } else { - if ( !isCollectionSnapshotValid(collection) ) { + if ( !isCollectionSnapshotValid( collection ) ) { throw new HibernateException( "could not reassociate uninitialized transient collection" ); } - CollectionPersister collectionPersister = getSession().getFactory() + CollectionPersister collectionPersister = session.getFactory() .getCollectionPersister( collection.getRole() ); - getSession().getPersistenceContext() + session.getPersistenceContext() .addUninitializedDetachedCollection( collectionPersister, collection ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/WrapVisitor.java b/hibernate-core/src/main/java/org/hibernate/event/internal/WrapVisitor.java index 0ddbc19b8b..880a238db0 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/WrapVisitor.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/WrapVisitor.java @@ -88,7 +88,7 @@ public class WrapVisitor extends ProxyVisitor { else { CollectionPersister persister = session.getFactory().getCollectionPersister( collectionType.getRole() ); - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); //TODO: move into collection type, so we can use polymorphism! if ( collectionType.hasHolder() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/event/spi/AbstractCollectionEvent.java b/hibernate-core/src/main/java/org/hibernate/event/spi/AbstractCollectionEvent.java index 5ebf1c4035..9b547f2567 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/spi/AbstractCollectionEvent.java +++ b/hibernate-core/src/main/java/org/hibernate/event/spi/AbstractCollectionEvent.java @@ -50,20 +50,20 @@ public abstract class AbstractCollectionEvent extends AbstractEvent { } protected static CollectionPersister getLoadedCollectionPersister( PersistentCollection collection, EventSource source ) { - CollectionEntry ce = source.getPersistenceContext().getCollectionEntry( collection ); + CollectionEntry ce = source.getPersistenceContextInternal().getCollectionEntry( collection ); return ( ce == null ? null : ce.getLoadedPersister() ); } protected static Object getLoadedOwnerOrNull( PersistentCollection collection, EventSource source ) { - return source.getPersistenceContext().getLoadedCollectionOwnerOrNull( collection ); + return source.getPersistenceContextInternal().getLoadedCollectionOwnerOrNull( collection ); } protected static Serializable getLoadedOwnerIdOrNull( PersistentCollection collection, EventSource source ) { - return source.getPersistenceContext().getLoadedCollectionOwnerIdOrNull( collection ); + return source.getPersistenceContextInternal().getLoadedCollectionOwnerIdOrNull( collection ); } protected static Serializable getOwnerIdOrNull( Object owner, EventSource source ) { - EntityEntry ownerEntry = source.getPersistenceContext().getEntry( owner ); + EntityEntry ownerEntry = source.getPersistenceContextInternal().getEntry( owner ); return ( ownerEntry == null ? null : ownerEntry.getId() ); } @@ -74,7 +74,7 @@ public abstract class AbstractCollectionEvent extends AbstractEvent { String entityName = ( collectionPersister == null ? null : collectionPersister.getOwnerEntityPersister().getEntityName() ); if ( affectedOwner != null ) { - EntityEntry ee = source.getPersistenceContext().getEntry( affectedOwner ); + EntityEntry ee = source.getPersistenceContextInternal().getEntry( affectedOwner ); if ( ee != null && ee.getEntityName() != null) { entityName = ee.getEntityName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java index 1193c8208d..cb3c0072cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractScrollableResults.java @@ -18,6 +18,7 @@ import java.util.Locale; import java.util.TimeZone; import org.hibernate.HibernateException; +import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.hql.internal.HolderInstantiator; @@ -101,10 +102,11 @@ public abstract class AbstractScrollableResults implements ScrollableResultsImpl // not absolutely necessary, but does help with aggressive release //session.getJDBCContext().getConnectionManager().closeQueryStatement( ps, resultSet ); - session.getJdbcCoordinator().getResourceRegistry().release( ps ); - session.getJdbcCoordinator().afterStatementExecution(); + final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator(); + jdbcCoordinator.getResourceRegistry().release( ps ); + jdbcCoordinator.afterStatementExecution(); try { - session.getPersistenceContext().getLoadContexts().cleanup( resultSet ); + session.getPersistenceContextInternal().getLoadContexts().cleanup( resultSet ); } catch (Throwable ignore) { // ignore this error for now diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CriteriaImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/CriteriaImpl.java index 60f74545a3..fd57fc3dca 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CriteriaImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CriteriaImpl.java @@ -305,7 +305,7 @@ public class CriteriaImpl implements Criteria, Serializable { } return ( isReadOnlyInitialized() ? readOnly : - getSession().getPersistenceContext().isDefaultReadOnly() + getSession().getPersistenceContextInternal().isDefaultReadOnly() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/IteratorImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/IteratorImpl.java index 92eba0050f..e6db72e7ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/IteratorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/IteratorImpl.java @@ -14,6 +14,7 @@ import java.util.NoSuchElementException; import org.hibernate.HibernateException; import org.hibernate.JDBCException; import org.hibernate.engine.HibernateIterator; +import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.event.spi.EventSource; import org.hibernate.hql.internal.HolderInstantiator; import org.hibernate.type.EntityType; @@ -63,7 +64,8 @@ public final class IteratorImpl implements HibernateIterator { public void close() throws JDBCException { if ( ps != null ) { LOG.debug( "Closing iterator" ); - session.getJdbcCoordinator().getResourceRegistry().release( ps ); + final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator(); + jdbcCoordinator.getResourceRegistry().release( ps ); try { session.getPersistenceContext().getLoadContexts().cleanup( rs ); } @@ -71,7 +73,7 @@ public final class IteratorImpl implements HibernateIterator { // ignore this error for now LOG.debugf( "Exception trying to cleanup load context : %s", ignore.getMessage() ); } - session.getJdbcCoordinator().afterStatementExecution(); + jdbcCoordinator.afterStatementExecution(); ps = null; rs = null; hasNext = false; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java index 63a0d93375..4fa6308fd8 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/ScrollableResultsImpl.java @@ -190,7 +190,7 @@ public class ScrollableResultsImpl extends AbstractScrollableResults implements return; } - final PersistenceContext persistenceContext = getSession().getPersistenceContext(); + final PersistenceContext persistenceContext = getSession().getPersistenceContextInternal(); persistenceContext.beforeLoad(); try { final Object result = getLoader().loadSingleRow( diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 3c3d0b1772..7a77ac16b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -2403,6 +2403,11 @@ public final class SessionImpl return persistenceContext; } + @Override + public PersistenceContext getPersistenceContextInternal() { + return persistenceContext; + } + @Override public SessionStatistics getStatistics() { pulseTransactionCoordinator(); @@ -3165,14 +3170,16 @@ public final class SessionImpl return; } - for ( Serializable pk : getPersistenceContext().getNaturalIdHelper() + final PersistenceContext persistenceContext = getPersistenceContextInternal(); + final boolean debugEnabled = log.isDebugEnabled(); + for ( Serializable pk : persistenceContext.getNaturalIdHelper() .getCachedPkResolutions( entityPersister ) ) { final EntityKey entityKey = generateEntityKey( pk, entityPersister ); - final Object entity = getPersistenceContext().getEntity( entityKey ); - final EntityEntry entry = getPersistenceContext().getEntry( entity ); + final Object entity = persistenceContext.getEntity( entityKey ); + final EntityEntry entry = persistenceContext.getEntry( entity ); if ( entry == null ) { - if ( log.isDebugEnabled() ) { + if ( debugEnabled ) { log.debug( "Cached natural-id/pk resolution linked to null EntityEntry in persistence context : " + MessageHelper.infoString( entityPersister, pk, getFactory() ) @@ -3190,7 +3197,7 @@ public final class SessionImpl continue; } - getPersistenceContext().getNaturalIdHelper().handleSynchronization( + persistenceContext.getNaturalIdHelper().handleSynchronization( entityPersister, pk, entity 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 3ae39c97f6..91d88564cf 100755 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -253,7 +253,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen @Override public Object immediateLoad(String entityName, Serializable id) throws HibernateException { - if ( getPersistenceContext().isLoadFinished() ) { + if ( getPersistenceContextInternal().isLoadFinished() ) { throw new SessionException( "proxies cannot be fetched by a stateless session" ); } // unless we are still in the process of handling a top-level load @@ -461,14 +461,15 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen public Object getEntityUsingInterceptor(EntityKey key) throws HibernateException { checkOpen(); - final Object result = getPersistenceContext().getEntity( key ); + final PersistenceContext persistenceContext = getPersistenceContext(); + final Object result = persistenceContext.getEntity( key ); if ( result != null ) { return result; } final Object newObject = getInterceptor().getEntity( key.getEntityName(), key.getIdentifier() ); if ( newObject != null ) { - getPersistenceContext().addEntity( key, newObject ); + persistenceContext.addEntity( key, newObject ); return newObject; } @@ -669,6 +670,12 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen return NO_INFLUENCERS; } + @Override + public PersistenceContext getPersistenceContextInternal() { + //In this case implemented the same as #getPersistenceContext + return temporaryPersistenceContext; + } + @Override public int executeNativeUpdate( NativeSQLQuerySpecification nativeSQLQuerySpecification, diff --git a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java index 3d3dd47ee9..e5ea804bd9 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -411,7 +411,7 @@ public abstract class Loader { session, queryParameters.isReadOnly( session ) ); - session.getPersistenceContext().initializeNonLazyCollections(); + session.getPersistenceContextInternal().initializeNonLazyCollections(); return result; } @@ -471,7 +471,7 @@ public abstract class Loader { session, queryParameters.isReadOnly( session ) ); - session.getPersistenceContext().initializeNonLazyCollections(); + session.getPersistenceContextInternal().initializeNonLazyCollections(); return result; } @@ -753,9 +753,10 @@ public abstract class Loader { if ( returnProxies ) { // now get an existing proxy for each row element (if there is one) + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); for ( int i = 0; i < entitySpan; i++ ) { Object entity = row[i]; - Object proxy = session.getPersistenceContext().proxyFor( persisters[i], keys[i], entity ); + Object proxy = persistenceContext.proxyFor( persisters[i], keys[i], entity ); if ( entity != proxy ) { // force the proxy to resolve itself ( (HibernateProxy) proxy ).getHibernateLazyInitializer().setImplementation( entity ); @@ -1066,6 +1067,7 @@ public abstract class Loader { final Loadable[] loadables = getEntityPersisters(); final String[] aliases = getAliases(); final String subselectQueryString = SubselectFetch.createSubselectFetchQueryFragment( queryParameters ); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); for ( Object key : keys ) { final EntityKey[] rowKeys = (EntityKey[]) key; for ( int i = 0; i < rowKeys.length; i++ ) { @@ -1081,7 +1083,7 @@ public abstract class Loader { namedParameterLocMap ); - session.getPersistenceContext() + persistenceContext .getBatchFetchQueue() .addSubselect( rowKeys[i], subselectFetch ); } @@ -1196,6 +1198,7 @@ public abstract class Loader { // split off from initializeEntity. It *must* occur after // endCollectionLoad to ensure the collection is in the // persistence context. + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); if ( hydratedObjects != null && hydratedObjects.size() > 0 ) { final Iterable postLoadEventListeners; @@ -1214,7 +1217,7 @@ public abstract class Loader { TwoPhaseLoad.postLoad( hydratedObject, session, post, postLoadEventListeners ); if ( afterLoadActions != null ) { for ( AfterLoadAction afterLoadAction : afterLoadActions ) { - final EntityEntry entityEntry = session.getPersistenceContext().getEntry( hydratedObject ); + final EntityEntry entityEntry = persistenceContext.getEntry( hydratedObject ); if ( entityEntry == null ) { // big problem throw new HibernateException( @@ -1233,7 +1236,7 @@ public abstract class Loader { final SharedSessionContractImplementor session, final CollectionPersister collectionPersister) { //this is a query and we are loading multiple instances of the same collection role - session.getPersistenceContext() + session.getPersistenceContextInternal() .getLoadContexts() .getCollectionLoadContext( (ResultSet) resultSetId ) .endLoadingCollections( collectionPersister ); @@ -1311,6 +1314,7 @@ public abstract class Loader { if ( owners != null ) { EntityType[] ownerAssociationTypes = getOwnerAssociationTypes(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); for ( int i = 0; i < keys.length; i++ ) { int owner = owners[i]; @@ -1318,7 +1322,6 @@ public abstract class Loader { EntityKey ownerKey = keys[owner]; if ( keys[i] == null && ownerKey != null ) { - final PersistenceContext persistenceContext = session.getPersistenceContext(); /*final boolean isPrimaryKey; final boolean isSpecialOneToOne; @@ -1375,7 +1378,7 @@ public abstract class Loader { final SharedSessionContractImplementor session) throws HibernateException, SQLException { - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final Serializable collectionRowKey = (Serializable) persister.readKey( rs, @@ -1451,6 +1454,7 @@ public abstract class Loader { // for each of the passed-in keys, to account for the possibility // that the collection is empty and has no rows in the result set CollectionPersister[] collectionPersisters = getCollectionPersisters(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); for ( CollectionPersister collectionPersister : collectionPersisters ) { for ( Serializable key : keys ) { //handle empty collections @@ -1461,7 +1465,7 @@ public abstract class Loader { ); } - session.getPersistenceContext() + persistenceContext .getLoadContexts() .getCollectionLoadContext( (ResultSet) resultSetId ) .getLoadingCollection( collectionPersister, key ); @@ -1529,7 +1533,7 @@ public abstract class Loader { final ResultSet rs, final SharedSessionContractImplementor session) throws HibernateException, SQLException { - Object version = session.getPersistenceContext().getEntry( entity ).getVersion(); + Object version = session.getPersistenceContextInternal().getEntry( entity ).getVersion(); if ( version != null ) { // null version means the object is in the process of being loaded somewhere else in the ResultSet @@ -1678,7 +1682,7 @@ public abstract class Loader { } if ( LockMode.NONE != requestedLockMode && upgradeLocks() ) { - final EntityEntry entry = session.getPersistenceContext().getEntry( object ); + final EntityEntry entry = session.getPersistenceContextInternal().getEntry( object ); if ( entry.getLockMode().lessThan( requestedLockMode ) ) { //we only check the version when _upgrading_ lock modes if ( persister.isVersioned() ) { @@ -1877,7 +1881,7 @@ public abstract class Loader { persister.getEntityMode(), session.getFactory() ); - session.getPersistenceContext().addEntity( euk, object ); + session.getPersistenceContextInternal().addEntity( euk, object ); } } @@ -2704,7 +2708,7 @@ public abstract class Loader { .getEntityMetamodel() .hasImmutableNaturalId(); - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. diff --git a/hibernate-core/src/main/java/org/hibernate/loader/collection/DynamicBatchingCollectionInitializerBuilder.java b/hibernate-core/src/main/java/org/hibernate/loader/collection/DynamicBatchingCollectionInitializerBuilder.java index 3440d8f842..ad1c253991 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/collection/DynamicBatchingCollectionInitializerBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/collection/DynamicBatchingCollectionInitializerBuilder.java @@ -84,7 +84,7 @@ public class DynamicBatchingCollectionInitializerBuilder extends BatchingCollect @Override public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException { // first, figure out how many batchable ids we have... - final Serializable[] batch = session.getPersistenceContext() + final Serializable[] batch = session.getPersistenceContextInternal() .getBatchFetchQueue() .getCollectionBatch( collectionPersister(), id, maxBatchSize ); final int numberOfIds = ArrayHelper.countNonNull( batch ); @@ -193,7 +193,7 @@ public class DynamicBatchingCollectionInitializerBuilder extends BatchingCollect ); try { - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. diff --git a/hibernate-core/src/main/java/org/hibernate/loader/collection/LegacyBatchingCollectionInitializerBuilder.java b/hibernate-core/src/main/java/org/hibernate/loader/collection/LegacyBatchingCollectionInitializerBuilder.java index 4aa67b9e96..ed94ca6aab 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/collection/LegacyBatchingCollectionInitializerBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/collection/LegacyBatchingCollectionInitializerBuilder.java @@ -67,7 +67,7 @@ public class LegacyBatchingCollectionInitializerBuilder extends BatchingCollecti @Override public void initialize(Serializable id, SharedSessionContractImplementor session) throws HibernateException { - Serializable[] batch = session.getPersistenceContext().getBatchFetchQueue() + Serializable[] batch = session.getPersistenceContextInternal().getBatchFetchQueue() .getCollectionBatch( collectionPersister(), id, batchSizes[0] ); for ( int i=0; i afterLoadActions) throws SQLException { - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final boolean defaultReadOnlyOrig = persistenceContext.isDefaultReadOnly(); if ( queryParameters.isReadOnlyInitialized() ) { // The read-only/modifiable mode for the query was explicitly set. diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/CollectionReferenceInitializerImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/CollectionReferenceInitializerImpl.java index 65548e1971..2d97519e84 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/CollectionReferenceInitializerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/CollectionReferenceInitializerImpl.java @@ -45,7 +45,7 @@ public class CollectionReferenceInitializerImpl implements CollectionReferenceIn try { // read the collection key for this reference for the current row. - final PersistenceContext persistenceContext = context.getSession().getPersistenceContext(); + final PersistenceContext persistenceContext = context.getSession().getPersistenceContextInternal(); final Serializable collectionRowKey = (Serializable) collectionReference.getCollectionPersister().readKey( resultSet, aliases.getCollectionColumnAliases().getSuffixedKeyAliases(), @@ -121,7 +121,7 @@ public class CollectionReferenceInitializerImpl implements CollectionReferenceIn Serializable collectionRowKey, ResultSet resultSet, ResultSetProcessingContextImpl context) { - final Object collectionOwner = context.getSession().getPersistenceContext().getCollectionOwner( + final Object collectionOwner = context.getSession().getPersistenceContextInternal().getCollectionOwner( collectionRowKey, collectionReference.getCollectionPersister() ); @@ -148,7 +148,7 @@ public class CollectionReferenceInitializerImpl implements CollectionReferenceIn @Override public void endLoading(ResultSetProcessingContextImpl context) { - context.getSession().getPersistenceContext() + context.getSession().getPersistenceContextInternal() .getLoadContexts() .getCollectionLoadContext( context.getResultSet() ) .endLoadingCollections( collectionReference.getCollectionPersister() ); diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/EntityReferenceInitializerImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/EntityReferenceInitializerImpl.java index f327ed4102..a9d5828bb4 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/EntityReferenceInitializerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/EntityReferenceInitializerImpl.java @@ -21,6 +21,7 @@ import org.hibernate.engine.internal.TwoPhaseLoad; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.EntityUniqueKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.CoreLogging; import org.hibernate.loader.EntityAliases; @@ -33,6 +34,7 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Loadable; import org.hibernate.persister.entity.UniqueKeyLoadable; import org.hibernate.pretty.MessageHelper; +import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.type.EntityType; import org.hibernate.type.Type; import org.hibernate.type.VersionType; @@ -283,7 +285,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize final EntityKey ownerEntityKey = fetchOwnerState.getEntityKey(); if ( ownerEntityKey != null ) { - context.getSession().getPersistenceContext().addNullProperty( + context.getSession().getPersistenceContextInternal().addNullProperty( ownerEntityKey, fetchedType.getPropertyName() ); @@ -301,7 +303,8 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize final Serializable id = entityKey.getIdentifier(); // Get the persister for the _subclass_ - final Loadable concreteEntityPersister = (Loadable) context.getSession().getFactory().getMetamodel().entityPersister( concreteEntityTypeName ); + final SharedSessionContractImplementor session = context.getSession(); + final Loadable concreteEntityPersister = (Loadable) session.getFactory().getMetamodel().entityPersister( concreteEntityTypeName ); if ( log.isTraceEnabled() ) { log.tracev( @@ -309,7 +312,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize MessageHelper.infoString( concreteEntityPersister, id, - context.getSession().getFactory() + session.getFactory() ) ); } @@ -322,10 +325,10 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize entityInstance, concreteEntityPersister, lockModeToAcquire, - context.getSession() + session ); - final EntityPersister rootEntityPersister = context.getSession().getFactory().getMetamodel().entityPersister( + final EntityPersister rootEntityPersister = session.getFactory().getMetamodel().entityPersister( concreteEntityPersister.getRootEntityName() ); final Object[] values; @@ -339,13 +342,13 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize ? entityReferenceAliases.getColumnAliases().getSuffixedPropertyAliases() : entityReferenceAliases.getColumnAliases().getSuffixedPropertyAliases( concreteEntityPersister ), context.getLoadPlan().areLazyAttributesForceFetched(), - context.getSession() + session ); context.getProcessingState( entityReference ).registerHydratedState( values ); } catch (SQLException e) { - throw context.getSession().getFactory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert( + throw session.getFactory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert( e, "Could not read entity state from ResultSet : " + entityKey ); @@ -365,7 +368,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize } } catch (SQLException e) { - throw context.getSession().getFactory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert( + throw session.getFactory().getServiceRegistry().getService( JdbcServices.class ).getSqlExceptionHelper().convert( e, "Could not read entity row-id from ResultSet : " + entityKey ); @@ -389,12 +392,12 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize EntityUniqueKey euk = new EntityUniqueKey( entityReference.getEntityPersister().getEntityName(), ukName, - type.semiResolve( values[index], context.getSession(), entityInstance ), + type.semiResolve( values[index], session, entityInstance ), type, concreteEntityPersister.getEntityMode(), - context.getSession().getFactory() + session.getFactory() ); - context.getSession().getPersistenceContext().addEntity( euk, entityInstance ); + session.getPersistenceContextInternal().addEntity( euk, entityInstance ); } } @@ -405,7 +408,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize rowId, entityInstance, lockModeToAcquire, - context.getSession() + session ); context.registerHydratedEntity( entityReference, entityKey, entityInstance ); @@ -457,7 +460,9 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize Object existing) { final LockMode requestedLockMode = context.resolveLockMode( entityReference ); if ( requestedLockMode != LockMode.NONE ) { - final LockMode currentLockMode = context.getSession().getPersistenceContext().getEntry( existing ).getLockMode(); + final SharedSessionContractImplementor session = context.getSession(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + final LockMode currentLockMode = persistenceContext.getEntry( existing ).getLockMode(); final boolean isVersionCheckNeeded = entityReference.getEntityPersister().isVersioned() && currentLockMode.lessThan( requestedLockMode ); @@ -466,7 +471,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize if ( isVersionCheckNeeded ) { //we only check the version when *upgrading* lock modes checkVersion( - context.getSession(), + session, resultSet, entityReference.getEntityPersister(), entityReferenceAliases.getColumnAliases(), @@ -474,7 +479,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize existing ); //we need to upgrade the lock mode to the mode requested - context.getSession().getPersistenceContext().getEntry( existing ).setLockMode( requestedLockMode ); + persistenceContext.getEntry( existing ).setLockMode( requestedLockMode ); } } } @@ -486,7 +491,7 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize EntityAliases entityAliases, EntityKey entityKey, Object entityInstance) { - final Object version = session.getPersistenceContext().getEntry( entityInstance ).getVersion(); + final Object version = session.getPersistenceContextInternal().getEntry( entityInstance ).getVersion(); if ( version != null ) { //null version means the object is in the process of being loaded somewhere else in the ResultSet @@ -508,8 +513,9 @@ public class EntityReferenceInitializerImpl implements EntityReferenceInitialize } if ( !versionType.isEqual( version, currentVersion ) ) { - if ( session.getFactory().getStatistics().isStatisticsEnabled() ) { - session.getFactory().getStatistics().optimisticFailure( persister.getEntityName() ); + final StatisticsImplementor statistics = session.getFactory().getStatistics(); + if ( statistics.isStatisticsEnabled() ) { + statistics.optimisticFailure( persister.getEntityName() ); } throw new StaleObjectStateException( persister.getEntityName(), entityKey.getIdentifier() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/EntityReturnReader.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/EntityReturnReader.java index e4ce770c49..fbb5bacdc8 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/EntityReturnReader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/EntityReturnReader.java @@ -52,7 +52,7 @@ public class EntityReturnReader implements ReturnReader { final Object entityInstance = context.getProcessingState( entityReturn ).getEntityInstance(); if ( context.shouldReturnProxies() ) { - final Object proxy = context.getSession().getPersistenceContext().proxyFor( + final Object proxy = context.getSession().getPersistenceContextInternal().proxyFor( entityReturn.getEntityPersister(), entityKey, entityInstance diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessingContextImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessingContextImpl.java index ae3f37b64f..e6109e9d2b 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessingContextImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessingContextImpl.java @@ -17,6 +17,7 @@ import java.util.Set; import org.hibernate.LockMode; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SubselectFetch; @@ -234,7 +235,7 @@ public class ResultSetProcessingContextImpl implements ResultSetProcessingContex throw new IllegalStateException( "Could not locate fetch owner EntityKey" ); } - session.getPersistenceContext().addNullProperty( + session.getPersistenceContextInternal().addNullProperty( ownerEntityKey, fetchedType.getPropertyName() ); @@ -351,8 +352,9 @@ public class ResultSetProcessingContextImpl implements ResultSetProcessingContex namedParameterLocMap ); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); for ( EntityKey key : entry.getValue() ) { - session.getPersistenceContext().getBatchFetchQueue().addSubselect( key, subselectFetch ); + persistenceContext.getBatchFetchQueue().addSubselect( key, subselectFetch ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessorImpl.java index 5f93d8bcca..886ce50149 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/ResultSetProcessorImpl.java @@ -14,6 +14,7 @@ import java.util.List; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.dialect.pagination.LimitHelper; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.QueryParameters; import org.hibernate.engine.spi.RowSelection; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -133,7 +134,7 @@ public class ResultSetProcessorImpl implements ResultSetProcessor { rowReader.finishUp( context, afterLoadActionList ); context.wrapUp(); - session.getPersistenceContext().initializeNonLazyCollections(); + session.getPersistenceContextInternal().initializeNonLazyCollections(); return loadResults; } @@ -155,15 +156,17 @@ public class ResultSetProcessorImpl implements ResultSetProcessor { // that the collection is empty and has no rows in the result set // // todo : move this inside CollectionReturn ? - CollectionPersister persister = ( (CollectionReturn) loadPlan.getReturns().get( 0 ) ).getCollectionPersister(); + final CollectionPersister persister = ( (CollectionReturn) loadPlan.getReturns().get( 0 ) ).getCollectionPersister(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + final boolean debugEnabled = LOG.isDebugEnabled(); for ( Serializable key : collectionKeys ) { - if ( LOG.isDebugEnabled() ) { + if ( debugEnabled ) { LOG.debugf( - "Preparing collection intializer : %s", + "Preparing collection initializer : %s", MessageHelper.collectionInfoString( persister, key, session.getFactory() ) ); } - session.getPersistenceContext() + persistenceContext .getLoadContexts() .getCollectionLoadContext( resultSet ) .getLoadingCollection( persister, key ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index c8a9a67cf9..b88e21cefa 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -730,7 +730,7 @@ public abstract class AbstractCollectionPersister return null; } - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); SubselectFetch subselect = persistenceContext.getBatchFetchQueue() .getSubselect( session.generateEntityKey( key, getOwnerEntityPersister() ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 8448028a8e..042894bd01 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -64,6 +64,7 @@ import org.hibernate.engine.internal.StatefulPersistenceContext; import org.hibernate.engine.internal.Versioning; import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; +import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.CachedNaturalIdValueSource; import org.hibernate.engine.spi.CascadeStyle; @@ -75,6 +76,7 @@ import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle; import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.Mapping; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.PersistenceContext.NaturalIdHelper; import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptor; @@ -1054,7 +1056,8 @@ public abstract class AbstractEntityPersister } public Object initializeLazyProperty(String fieldName, Object entity, SharedSessionContractImplementor session) { - final EntityEntry entry = session.getPersistenceContext().getEntry( entity ); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + final EntityEntry entry = persistenceContext.getEntry( entity ); final PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) entity ).$$_hibernate_getInterceptor(); assert interceptor != null : "Expecting bytecode interceptor to be non-null"; @@ -1075,11 +1078,11 @@ public abstract class AbstractEntityPersister // see if there is already a collection instance associated with the session // NOTE : can this ever happen? final Serializable key = getCollectionKey( persister, entity, entry, session ); - PersistentCollection collection = session.getPersistenceContext().getCollection( new CollectionKey( persister, key ) ); + PersistentCollection collection = persistenceContext.getCollection( new CollectionKey( persister, key ) ); if ( collection == null ) { collection = collectionType.instantiate( session, persister, key ); collection.setOwner( entity ); - session.getPersistenceContext().addUninitializedCollection( persister, collection, key ); + persistenceContext.addUninitializedCollection( persister, collection, key ); } // // HHH-11161 Initialize, if the collection is not extra lazy @@ -1089,12 +1092,12 @@ public abstract class AbstractEntityPersister interceptor.attributeInitialized( fieldName ); if ( collectionType.isArrayType() ) { - session.getPersistenceContext().addCollectionHolder( collection ); + persistenceContext.addCollectionHolder( collection ); } // update the "state" of the entity's EntityEntry to over-write UNFETCHED_PROPERTY reference // for the collection to the just loaded collection - final EntityEntry ownerEntry = session.getPersistenceContext().getEntry( entity ); + final EntityEntry ownerEntry = persistenceContext.getEntry( entity ); if ( ownerEntry == null ) { // not good throw new AssertionFailure( @@ -3614,7 +3617,7 @@ public abstract class AbstractEntityPersister final boolean[] propsToUpdate; final String[] updateStrings; - EntityEntry entry = session.getPersistenceContext().getEntry( object ); + EntityEntry entry = session.getPersistenceContextInternal().getEntry( object ); // Ensure that an immutable or non-modifiable entity is not being updated unless it is // in the process of being deleted. @@ -3751,9 +3754,10 @@ public abstract class AbstractEntityPersister // // Note, it potentially could be a proxy, so doAfterTransactionCompletion the location the safe way... final EntityKey key = session.generateEntityKey( id, this ); - Object entity = session.getPersistenceContext().getEntity( key ); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + Object entity = persistenceContext.getEntity( key ); if ( entity != null ) { - EntityEntry entry = session.getPersistenceContext().getEntry( entity ); + EntityEntry entry = persistenceContext.getEntry( entity ); loadedState = entry.getLoadedState(); } } @@ -4686,13 +4690,14 @@ public abstract class AbstractEntityPersister return; } - final NaturalIdHelper naturalIdHelper = session.getPersistenceContext().getNaturalIdHelper(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + final NaturalIdHelper naturalIdHelper = persistenceContext.getNaturalIdHelper(); final Serializable id = getIdentifier( entity, session ); // for reattachment of mutable natural-ids, we absolutely positively have to grab the snapshot from the // database, because we have no other way to know if the state changed while detached. final Object[] naturalIdSnapshot; - final Object[] entitySnapshot = session.getPersistenceContext().getDatabaseSnapshot( id, this ); + final Object[] entitySnapshot = persistenceContext.getDatabaseSnapshot( id, this ); if ( entitySnapshot == StatefulPersistenceContext.NO_ROW ) { naturalIdSnapshot = null; } @@ -5289,20 +5294,20 @@ public abstract class AbstractEntityPersister Object[] snapshot = new Object[naturalIdPropertyCount]; try { - PreparedStatement ps = session - .getJdbcCoordinator() + final JdbcCoordinator jdbcCoordinator = session.getJdbcCoordinator(); + PreparedStatement ps = jdbcCoordinator .getStatementPreparer() .prepareStatement( sql ); try { getIdentifierType().nullSafeSet( ps, id, 1, session ); - ResultSet rs = session.getJdbcCoordinator().getResultSetReturn().extract( ps ); + ResultSet rs = jdbcCoordinator.getResultSetReturn().extract( ps ); try { //if there is no resulting row, return null if ( !rs.next() ) { return null; } final EntityKey key = session.generateEntityKey( id, this ); - Object owner = session.getPersistenceContext().getEntity( key ); + Object owner = session.getPersistenceContextInternal().getEntity( key ); for ( int i = 0; i < naturalIdPropertyCount; i++ ) { snapshot[i] = extractionTypes[i].hydrate( rs, getPropertyAliases( @@ -5317,12 +5322,12 @@ public abstract class AbstractEntityPersister return snapshot; } finally { - session.getJdbcCoordinator().getResourceRegistry().release( rs, ps ); + jdbcCoordinator.getResourceRegistry().release( rs, ps ); } } finally { - session.getJdbcCoordinator().getResourceRegistry().release( ps ); - session.getJdbcCoordinator().afterStatementExecution(); + jdbcCoordinator.getResourceRegistry().release( ps ); + jdbcCoordinator.afterStatementExecution(); } } catch (SQLException e) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/NamedQueryLoader.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/NamedQueryLoader.java index 612f6a12ab..ead92404b4 100755 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/NamedQueryLoader.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/NamedQueryLoader.java @@ -77,7 +77,7 @@ public final class NamedQueryLoader implements UniqueEntityLoader { // now look up the object we are really interested in! // (this lets us correctly handle proxies and multi-row or multi-column queries) - return session.getPersistenceContext().getEntity( session.generateEntityKey( id, persister ) ); + return session.getPersistenceContextInternal().getEntity( session.generateEntityKey( id, persister ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/pretty/MessageHelper.java b/hibernate-core/src/main/java/org/hibernate/pretty/MessageHelper.java index 8527b5e9a6..8a16c1c4a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/pretty/MessageHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/pretty/MessageHelper.java @@ -263,7 +263,7 @@ public final class MessageHelper { } else { Object collectionOwner = collection == null ? null : collection.getOwner(); - EntityEntry entry = collectionOwner == null ? null : session.getPersistenceContext().getEntry(collectionOwner); + EntityEntry entry = collectionOwner == null ? null : session.getPersistenceContextInternal().getEntry(collectionOwner); ownerKey = entry == null ? null : entry.getId(); } s.append( ownerIdentifierType.toLoggableString( diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java index 49c83a09a0..a1b7cbcac5 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java @@ -97,7 +97,7 @@ public class PropertyAccessStrategyBackRefImpl implements PropertyAccessStrategy return UNKNOWN; } else { - return session.getPersistenceContext().getOwnerId( entityName, propertyName, owner, mergeMap ); + return session.getPersistenceContextInternal().getOwnerId( entityName, propertyName, owner, mergeMap ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java index d6c0cc6348..ad7280c7a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java @@ -80,7 +80,7 @@ public class PropertyAccessStrategyIndexBackRefImpl implements PropertyAccessStr return PropertyAccessStrategyBackRefImpl.UNKNOWN; } else { - return session.getPersistenceContext().getIndexInOwner( entityName, propertyName, owner, mergeMap ); + return session.getPersistenceContextInternal().getIndexInOwner( entityName, propertyName, owner, mergeMap ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java b/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java index c430e7017a..917f620412 100644 --- a/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java @@ -15,6 +15,7 @@ import org.hibernate.SessionException; import org.hibernate.TransientObjectException; import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.engine.spi.EntityKey; +import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.CoreLogging; @@ -255,7 +256,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer { getIdentifier(), session.getFactory().getMetamodel().entityPersister( getEntityName() ) ); - final Object entity = session.getPersistenceContext().getEntity( key ); + final Object entity = session.getPersistenceContextInternal().getEntity( key ); if ( entity != null ) { setImplementation( entity ); } @@ -299,7 +300,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer { private Object getProxyOrNull() { final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() ); if ( entityKey != null && session != null && session.isOpenOrWaitingForAutoClose() ) { - return session.getPersistenceContext().getProxy( entityKey ); + return session.getPersistenceContextInternal().getProxy( entityKey ); } return null; } @@ -319,7 +320,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer { @Override public final Object getImplementation(SharedSessionContractImplementor s) throws HibernateException { final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), s, getEntityName() ); - return (entityKey == null ? null : s.getPersistenceContext().getEntity( entityKey )); + return ( entityKey == null ? null : s.getPersistenceContext().getEntity( entityKey ) ); } /** @@ -369,8 +370,9 @@ public abstract class AbstractLazyInitializer implements LazyInitializer { this.readOnly = readOnly; if ( initialized ) { EntityKey key = generateEntityKeyOrNull( getIdentifier(), session, getEntityName() ); - if ( key != null && session.getPersistenceContext().containsEntity( key ) ) { - session.getPersistenceContext().setReadOnly( target, readOnly ); + final PersistenceContext persistenceContext = session.getPersistenceContext(); + if ( key != null && persistenceContext.containsEntity( key ) ) { + persistenceContext.setReadOnly( target, readOnly ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java index 8598fbfc77..6807f0e9c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/internal/AbstractProducedQuery.java @@ -247,7 +247,7 @@ public abstract class AbstractProducedQuery implements QueryImplementor { @Override public boolean isReadOnly() { return ( readOnly == null ? - producer.getPersistenceContext().isDefaultReadOnly() : + producer.getPersistenceContextInternal().isDefaultReadOnly() : readOnly ); } diff --git a/hibernate-core/src/main/java/org/hibernate/stat/internal/SessionStatisticsImpl.java b/hibernate-core/src/main/java/org/hibernate/stat/internal/SessionStatisticsImpl.java index 371bd84894..3eb1055513 100755 --- a/hibernate-core/src/main/java/org/hibernate/stat/internal/SessionStatisticsImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/stat/internal/SessionStatisticsImpl.java @@ -24,19 +24,19 @@ public class SessionStatisticsImpl implements SessionStatistics { } public int getEntityCount() { - return session.getPersistenceContext().getNumberOfManagedEntities(); + return session.getPersistenceContextInternal().getNumberOfManagedEntities(); } public int getCollectionCount() { - return session.getPersistenceContext().getCollectionEntries().size(); + return session.getPersistenceContextInternal().getCollectionEntries().size(); } public Set getEntityKeys() { - return Collections.unmodifiableSet( session.getPersistenceContext().getEntitiesByKey().keySet() ); + return Collections.unmodifiableSet( session.getPersistenceContextInternal().getEntitiesByKey().keySet() ); } public Set getCollectionKeys() { - return Collections.unmodifiableSet( session.getPersistenceContext().getCollectionsByKey().keySet() ); + return Collections.unmodifiableSet( session.getPersistenceContextInternal().getCollectionsByKey().keySet() ); } public String toString() { diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java index 076e4ddb15..cd7dba42ef 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java @@ -385,7 +385,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer { public void setIdentifier(Object entity, Serializable id, EntityMode entityMode, SharedSessionContractImplementor session) { final Object[] extractedValues = mappedIdentifierType.getPropertyValues( id, entityMode ); final Object[] injectionValues = new Object[extractedValues.length]; - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); for ( int i = 0; i < virtualIdComponent.getSubtypes().length; i++ ) { final Type virtualPropertyType = virtualIdComponent.getSubtypes()[i]; final Type idClassPropertyType = mappedIdentifierType.getSubtypes()[i]; @@ -438,7 +438,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer { } if ( session != null ) { - final EntityEntry pcEntry = session.getPersistenceContext().getEntry( entity ); + final EntityEntry pcEntry = session.getPersistenceContextInternal().getEntry( entity ); if ( pcEntry != null ) { // entity managed; return ID. return pcEntry.getId(); diff --git a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java index 8df290c6cb..2b2a1dd602 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java @@ -369,8 +369,9 @@ public abstract class CollectionType extends AbstractType implements Association * @return The collection owner's key */ public Serializable getKeyOfOwner(Object owner, SharedSessionContractImplementor session) { + final PersistenceContext pc = session.getPersistenceContextInternal(); - EntityEntry entityEntry = session.getPersistenceContext().getEntry( owner ); + EntityEntry entityEntry = pc.getEntry( owner ); if ( entityEntry == null ) { // This just handles a particular case of component // projection, perhaps get rid of it and throw an exception @@ -637,7 +638,7 @@ public abstract class CollectionType extends AbstractType implements Association } - CollectionEntry ce = session.getPersistenceContext().getCollectionEntry( result ); + CollectionEntry ce = session.getPersistenceContextInternal().getCollectionEntry( result ); if ( ce != null ) { ce.resetStoredSnapshot( result, targetSnapshot ); } @@ -769,7 +770,7 @@ public abstract class CollectionType extends AbstractType implements Association public Object getCollection(Serializable key, SharedSessionContractImplementor session, Object owner, Boolean overridingEager) { final CollectionPersister persister = getPersister( session ); - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final CollectionKey collectionKey = new CollectionKey( persister, key ); // check if collection is currently being loaded diff --git a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java index 15490e7da7..5aa766b7b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ComponentType.java @@ -588,7 +588,7 @@ public class ComponentType extends AbstractType implements CompositeType, Proced if ( componentTuplizer.hasParentProperty() && parent != null ) { componentTuplizer.setParent( result, - session.getPersistenceContext().proxyFor( parent ), + session.getPersistenceContextInternal().proxyFor( parent ), session.getFactory() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/EntityType.java b/hibernate-core/src/main/java/org/hibernate/type/EntityType.java index 19e9b34754..207e82ac4d 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EntityType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/EntityType.java @@ -739,7 +739,7 @@ public abstract class EntityType extends AbstractType implements AssociationType session.getFactory() ); - final PersistenceContext persistenceContext = session.getPersistenceContext(); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); Object result = persistenceContext.getEntity( euk ); if ( result == null ) { result = persister.loadByUniqueKey( uniqueKeyPropertyName, key, session ); diff --git a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java index 473e4dc407..a461bfe5c3 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/ManyToOneType.java @@ -204,8 +204,9 @@ public class ManyToOneType extends EntityType { final EntityPersister persister = getAssociatedEntityPersister( session.getFactory() ); if ( persister.isBatchLoadable() ) { final EntityKey entityKey = session.generateEntityKey( id, persister ); - if ( !session.getPersistenceContext().containsEntity( entityKey ) ) { - session.getPersistenceContext().getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + if ( !persistenceContext.containsEntity( entityKey ) ) { + persistenceContext.getBatchFetchQueue().addBatchLoadableEntityKey( entityKey ); } } } @@ -238,7 +239,8 @@ public class ManyToOneType extends EntityType { public Object resolve(Object value, SharedSessionContractImplementor session, Object owner, Boolean overridingEager) throws HibernateException { Object resolvedValue = super.resolve(value, session, owner, overridingEager); if ( isLogicalOneToOne && value != null && getPropertyName() != null ) { - EntityEntry entry = session.getPersistenceContext().getEntry( owner ); + final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); + EntityEntry entry = persistenceContext.getEntry( owner ); if ( entry != null ) { final Loadable ownerPersister = (Loadable) session.getFactory().getMetamodel().entityPersister( entry.getEntityName() ); EntityUniqueKey entityKey = new EntityUniqueKey( @@ -249,7 +251,7 @@ public class ManyToOneType extends EntityType { ownerPersister.getEntityMode(), session.getFactory() ); - session.getPersistenceContext().addEntity( entityKey, owner ); + persistenceContext.addEntity( entityKey, owner ); } } return resolvedValue; diff --git a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java index 53c058e8d0..8b90dbd99f 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/OneToOneType.java @@ -103,7 +103,7 @@ public class OneToOneType extends EntityType { final EntityPersister ownerPersister = session.getFactory().getMetamodel().entityPersister( entityName ); final Serializable id = session.getContextEntityIdentifier( owner ); final EntityKey entityKey = session.generateEntityKey( id, ownerPersister ); - return session.getPersistenceContext().isPropertyNull( entityKey, getPropertyName() ); + return session.getPersistenceContextInternal().isPropertyNull( entityKey, getPropertyName() ); } else { return false; diff --git a/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchNotFoundIgnoreDefaultStyleTest.java b/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchNotFoundIgnoreDefaultStyleTest.java index 01871c44c2..f992d5c407 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchNotFoundIgnoreDefaultStyleTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/batchfetch/BatchFetchNotFoundIgnoreDefaultStyleTest.java @@ -283,7 +283,7 @@ public class BatchFetchNotFoundIgnoreDefaultStyleTest extends BaseCoreFunctional final EntityPersister persister = sessionImplementor.getFactory().getMetamodel().entityPersister( Task.class ); final BatchFetchQueue batchFetchQueue = - sessionImplementor.getPersistenceContext().getBatchFetchQueue(); + sessionImplementor.getPersistenceContextInternal().getBatchFetchQueue(); assertEquals( expected, batchFetchQueue.containsEntityKey( new EntityKey( id, persister ) ) ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/collection/dereferenced/AbstractDereferencedCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/collection/dereferenced/AbstractDereferencedCollectionTest.java index 55b77c2793..363b382a00 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/collection/dereferenced/AbstractDereferencedCollectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/collection/dereferenced/AbstractDereferencedCollectionTest.java @@ -49,10 +49,10 @@ import static org.junit.Assert.assertTrue; public abstract class AbstractDereferencedCollectionTest extends BaseCoreFunctionalTestCase { protected EntityEntry getEntityEntry(Session s, Object entity) { - return ( (SessionImplementor) s ).getPersistenceContext().getEntry( entity ); + return ( (SessionImplementor) s ).getPersistenceContextInternal().getEntry( entity ); } protected CollectionEntry getCollectionEntry(Session s, PersistentCollection collection) { - return ( (SessionImplementor) s ).getPersistenceContext().getCollectionEntry( collection ); + return ( (SessionImplementor) s ).getPersistenceContextInternal().getCollectionEntry( collection ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/event/collection/detached/AggregatedCollectionEventListener.java b/hibernate-core/src/test/java/org/hibernate/test/event/collection/detached/AggregatedCollectionEventListener.java index 3a850ebe0e..57d5fcfa62 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/event/collection/detached/AggregatedCollectionEventListener.java +++ b/hibernate-core/src/test/java/org/hibernate/test/event/collection/detached/AggregatedCollectionEventListener.java @@ -117,7 +117,7 @@ public class AggregatedCollectionEventListener this.event = event; // make a copy of the collection? this.snapshotAtTimeOfEventHandling = event.getSession() - .getPersistenceContext() + .getPersistenceContextInternal() .getCollectionEntry( event.getCollection() ) .getSnapshot(); } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java index 6fa74b5cd4..7aa978148b 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/event/spi/BaseEnversCollectionEventListener.java @@ -44,7 +44,7 @@ public abstract class BaseEnversCollectionEventListener extends BaseEnversEventL } protected final CollectionEntry getCollectionEntry(AbstractCollectionEvent event) { - return event.getSession().getPersistenceContext().getCollectionEntry( event.getCollection() ); + return event.getSession().getPersistenceContextInternal().getCollectionEntry( event.getCollection() ); } protected final void onCollectionAction( diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java index 174d5f2b36..5a232f3be1 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/entities/mapper/relation/AbstractCollectionMapper.java @@ -229,7 +229,7 @@ public abstract class AbstractCollectionMapper extends AbstractPropertyMapper PersistentCollection collection) { // First attempt to resolve the persister from the collection entry if ( collection != null ) { - CollectionEntry collectionEntry = session.getPersistenceContext().getCollectionEntry( collection ); + CollectionEntry collectionEntry = session.getPersistenceContextInternal().getCollectionEntry( collection ); if ( collectionEntry != null ) { CollectionPersister collectionPersister = collectionEntry.getCurrentPersister(); if ( collectionPersister != null ) {