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