| I believe that a ManagedEntity can only be associated with a single PersistenceContext, We can do checks to see if a mutable ManagedEntity is still associated with the other PersistenceContext. We do something similar for AbstractPersistentCollection#setCurrentSession I agree we cannot add EntityEntry#getPersistenceContext. It's not ideal, but, when possible, we could cast to AbstractEntityEntry and call AbstractEntityEntry#getPersistenceContext. We would still have a problem with immutable entities though because ImmutableEntityEntry#getPersistenceContext would return null. |