@@ -208,20 +208,20 @@ private void putImmutableManagedEntity(ManagedEntity managed, int instanceId, Im
208208 private void checkNotAssociatedWithOtherPersistenceContextIfMutable (ManagedEntity managedEntity ) {
209209 // we only have to check mutable managedEntity
210210 final var entityEntry = (EntityEntryImpl ) managedEntity .$$_hibernate_getEntityEntry ();
211- if ( entityEntry != null
212- && entityEntry .getPersister (). isMutable ()
213- && entityEntry . getPersistenceContext () != null
214- && entityEntry . getPersistenceContext () != persistenceContext ) {
215- if ( entityEntry . getPersistenceContext (). getSession (). isOpen () ) {
216- // NOTE: otherPersistenceContext may be operating on the entityEntry in a different thread .
217- // it is not safe to associate entityEntry with this EntityEntryContext.
218- throw new HibernateException (
219- "Illegal attempt to associate a ManagedEntity with two open persistence contexts: " + entityEntry
220- );
221- }
222- else {
223- // otherPersistenceContext is associated with a closed PersistenceContext
224- CORE_LOGGER . stalePersistenceContextInEntityEntry ( entityEntry . toString () );
211+ if ( entityEntry != null && entityEntry . getPersister (). isMutable () ) {
212+ final var entryPersistenceContext = entityEntry .getPersistenceContext ();
213+ if ( entryPersistenceContext != null && entryPersistenceContext != persistenceContext ) {
214+ if ( entryPersistenceContext . getSession (). isOpen () ) {
215+ // NOTE: otherPersistenceContext may be operating on the entityEntry in a different thread.
216+ // it is not safe to associate entityEntry with this EntityEntryContext .
217+ throw new HibernateException (
218+ "Illegal attempt to associate a ManagedEntity with two open persistence contexts: " + entityEntry
219+ );
220+ }
221+ else {
222+ // otherPersistenceContext is associated with a closed PersistenceContext
223+ CORE_LOGGER . stalePersistenceContextInEntityEntry ( entityEntry . toString () );
224+ }
225225 }
226226 }
227227 }
0 commit comments