Is there a way to check if two EntityManagers instances represents the same PersistenceContext?
The container can use a proxy for implementation of the EntityManager, so I don’t think that checking the reference of the injected EntityManager and comparing it (in other words doing “==” comparison) is enough to say that it represents the same PersistenceContext, right?
I have debugged the scenario with two entity managers with
@PersistenceContextWhen injected persistent context with same unit, comparing
entityManager.getDelegate()which returns the vendor specific underlying object are same & both points to the same entity manager factory.With different units, the delegates obtained & entity manager factory, both were different.
Further can refer this post.
Note : The environment used is Java EE 5, there were several other methods like
getMetaModel(),unwrap(object),getProperties()etc. can provide further information.