• Post Reply Bookmark Topic Watch Topic
  • New Topic

Test PersistenceContexts for equality  RSS feed

 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Ranchers!

I've originally asked the question on StackOverflow (http://stackoverflow.com/questions/8083752/test-two-persistencecontexts-for-equality), but unfortunately no one replied.

Is there a way to check if two EntityManagers instances represents the same PersistenceContext?

 
lucio bosque
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you just oveeride equals method ?
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Lucio, the entity manager instance injection is controlled by the container. The implementation of the EntityManager interface is made by the concrete JPA-provider.

I am looking for jpa-provider agnostic method of checking if two EntityManagers refers to the same PersistenceContext (because as I understand the specification - there is no requirement that one EntityManager reflects exactly one PersistenceContext).
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need that check?
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jaikiran

Sometimes I see posts (i.e. in StackOverflow) where people are confused if the EntityManager reflects the same PersistenceContext or not (i.e. when calling EJB with TransactionAttribute set to REQUIRES_NEW). Well, I know that the specification mandates it to be a new PersistenceContext bound to the fresh transaction, but I wonder if there is a way of confirming it.

Do you think that such equality check is:
- possible,
- is vendor specific,
- is not possible, as it is a implementation details of the jpa-provider?
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!