• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When is a Persistent Context created ?

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I read in the specs 5.6.1:

A new persistence context begins when the container-managed entity manager is invoked in the scope of an active JTA transaction, and there is no current persistence context already associated with the JTA transaction. The persistence context is created and then associated with the JTA transaction.


and, in the same section:

If the entity manager is invoked outside the scope of a transaction, any entities loaded from the database will immediately become detached at the end of the method call.



In the second case, the persistence context is created too, isn't it ?
So the good answer to "When is a Persistent Context created while using container managed EntityManager?" is

"as soon as an EntityManager is invoked." ?

Thanks for your opinion...

Beno�t
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look at footnote 36 at the bottom of page 121 of the JSR 220 persistence spec:

"Specifically, when one of the methods of the EntityManager interface is invoked."

As far as container-managed transaction-scoped entity managers are concerned, "every time an operation is invoked on the entity manager, it checks to see if a persistence context is associated with the transaction. If it finds one, the entity manager will use this persistence context. If it doesn't find one, then it creates a new persistence context and associates it with the transaction. When the transaction ends, the persistence context goes away."

source: pg. 113 of Pro EJB3 JPA by Mike Keith

As far as container-managed extended-scoped entity managers are concerned, "extended entity managers create a persistence context when a stateful session bean instance is created and lasts until the bean is removed."

pg. 116

I highly recommend you read this entire book, Keith was a co-spec lead on JSR220.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Seam Rocks",
You have already be warned once about the ranch's Naming Policy. Please read it and change your name accordingly.
 
Uchana Jackson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
done
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but I think that you missed the part on obviously fake names. Please take some time to carefully read through the policy and set your name properly.
 
Uchana Jackson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok you got me, as if it matters.
 
Benoît de Chateauvieux
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Uchana Jackson,

Thanks for your answer.
I understand what you said: a persistence context is created when the entity manager is invoked in the scope of a JTA transaction.

But what if the method invoked has a NOT_SUPPORTED transaction demarcation ?

Thanks,

Beno�t
 
please buy my thing and then I'll have more money:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic