We're updating the issue view to help you get more done. 

StatefulPersistenceContext.entityEntryContext does not work properly for ManagedEntity associated with a different StatefulPersistenceContext

Description

EntityEntryContext does not "know" which StatefulPersistenceContext owns it. This can cause problems when a ManagedEntity that is associated with a different StatefulPersistenceContext is passed to EntityEntryContext methods.

When a ManagedEntity is passed as an argument to an EntityEntryContext method, the method always assumes that the ManagedEntity is associated with the EntityEntryContext if {{ManagedEntity.$$_hibernate_getEntityEntry() != null }}.

If the ManagedEntity is associated with a different EntityEntryContext, then methods like #addEntityEntry and #removeEntityEntry will overwrite data in the ManagedEntity, causing inconsistencies in the other EntityEntryContext.

In addition, Session.contains( managedEntity) will always return true:

{{s = getFactory().openSession()
loadedParent = s.get( Parent.class, loadedParent.getId() );
managedParent = (ManagedEntity) loadedParent;
// now open a new session (s2) and assert that the new session does not contain it
Session s2 = getFactory().openSession();
assertFalse( s2.contains( managedParent ) );}} <== FAILS

EntityEntryContext should have a reference to its owning StatefulPersistenceContext. That way it can determine if ManagedEntity.$$_hibernate_getEntityEntry() is associated with the same StatefulPersistenceContext, so EntityEntryContext methods can deal with the ManagedEntity appropriately.

Environment

None

Status

Assignee

Gail Badner

Reporter

Gail Badner

Labels

Components

Fix versions

Affects versions

5.1.0
5.0.9
5.2.0

Priority

Critical