Uploaded image for project: 'Hibernate ORM'
  1. HHH-10795

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

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      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.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: