diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java index becae03151..b9c5a13b7c 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/AbstractEntityEntry.java @@ -290,10 +290,10 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry { ( (SelfDirtinessTracker) entity ).$$_hibernate_clearDirtyAttributes(); } - persistenceContext.getSession() + getPersistenceContext().getSession() .getFactory() .getCustomEntityDirtinessStrategy() - .resetDirty( entity, getPersister(), (Session) persistenceContext.getSession() ); + .resetDirty( entity, getPersister(), (Session) getPersistenceContext().getSession() ); } @Override @@ -340,15 +340,14 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry { @SuppressWarnings( {"SimplifiableIfStatement"}) private boolean isUnequivocallyNonDirty(Object entity) { - - if(entity instanceof SelfDirtinessTracker) { + if (entity instanceof SelfDirtinessTracker) { return ! ( (SelfDirtinessTracker) entity ).$$_hibernate_hasDirtyAttributes(); } final CustomEntityDirtinessStrategy customEntityDirtinessStrategy = - persistenceContext.getSession().getFactory().getCustomEntityDirtinessStrategy(); - if ( customEntityDirtinessStrategy.canDirtyCheck( entity, getPersister(), (Session) persistenceContext.getSession() ) ) { - return ! customEntityDirtinessStrategy.isDirty( entity, getPersister(), (Session) persistenceContext.getSession() ); + getPersistenceContext().getSession().getFactory().getCustomEntityDirtinessStrategy(); + if ( customEntityDirtinessStrategy.canDirtyCheck( entity, getPersister(), (Session) getPersistenceContext().getSession() ) ) { + return ! customEntityDirtinessStrategy.isDirty( entity, getPersister(), (Session) getPersistenceContext().getSession() ); } if ( getPersister().hasMutableProperties() ) { @@ -407,7 +406,7 @@ public abstract class AbstractEntityEntry implements Serializable, EntityEntry { } setStatus( Status.MANAGED ); loadedState = getPersister().getPropertyValues( entity ); - persistenceContext.getNaturalIdHelper().manageLocalNaturalIdCrossReference( + getPersistenceContext().getNaturalIdHelper().manageLocalNaturalIdCrossReference( persister, id, loadedState, diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/ImmutableEntityEntry.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/ImmutableEntityEntry.java index b8cf43faea..b28c784fe4 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/ImmutableEntityEntry.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/ImmutableEntityEntry.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; +import org.hibernate.AssertionFailure; import org.hibernate.EntityMode; import org.hibernate.LockMode; import org.hibernate.UnsupportedLockAttemptException; @@ -51,8 +52,20 @@ public final class ImmutableEntityEntry extends AbstractEntityEntry { final boolean disableVersionIncrement, final boolean lazyPropertiesAreUnfetched, final PersistenceContext persistenceContext) { - this( status, loadedState, rowId, id, version, lockMode, existsInDatabase, - persister,disableVersionIncrement, lazyPropertiesAreUnfetched, null ); + this( + status, + loadedState, + rowId, + id, + version, + lockMode, + existsInDatabase, + persister, + disableVersionIncrement, + lazyPropertiesAreUnfetched, + // purposefully do not pass along the session/persistence-context : HHH-10251 + null + ); } public ImmutableEntityEntry( @@ -68,8 +81,20 @@ public final class ImmutableEntityEntry extends AbstractEntityEntry { final boolean lazyPropertiesAreUnfetched, final PersistenceContext persistenceContext) { - super( status, loadedState, rowId, id, version, lockMode, existsInDatabase, persister, - disableVersionIncrement, lazyPropertiesAreUnfetched, null ); + super( + status, + loadedState, + rowId, + id, + version, + lockMode, + existsInDatabase, + persister, + disableVersionIncrement, + lazyPropertiesAreUnfetched, + // purposefully do not pass along the session/persistence-context : HHH-10251 + null + ); } /** @@ -98,13 +123,15 @@ public final class ImmutableEntityEntry extends AbstractEntityEntry { @Override public void setLockMode(LockMode lockMode) { - - switch(lockMode) { - case NONE : case READ: + switch ( lockMode ) { + case NONE: + case READ: { setCompressedValue( EnumState.LOCK_MODE, lockMode ); break; - default: - throw new UnsupportedLockAttemptException("Lock mode not supported"); + } + default: { + throw new UnsupportedLockAttemptException( "Lock mode not supported" ); + } } } @@ -140,12 +167,13 @@ public final class ImmutableEntityEntry extends AbstractEntityEntry { ois.readBoolean(), ois.readBoolean(), ois.readBoolean(), - persistenceContext + null ); } - public PersistenceContext getPersistenceContext(){ - return persistenceContext; + @Override + public PersistenceContext getPersistenceContext() { + throw new AssertionFailure( "Session/PersistenceContext is not available from an ImmutableEntityEntry" ); } }