• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Test PersistenceContexts for equality  RSS feed

 
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?

 
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).
 
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!