Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubt on PersistenceContext Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Doubt on PersistenceContext" Watch "Doubt on PersistenceContext" New topic
Author

Doubt on PersistenceContext

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

Whys is that only those EntityManager instances injected with the @PersistenceContext annotation are transaction-scoped?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You mean, why application-managed persistence contexts are not transaction-scoped ? You don't want the container to mess up with your application-managed stuff (EntityManager, persistence context), do you ? You are the one who controls the scope of the entity manager and its persistence context. You are the one who must close the entity manager. Why would you need a transaction scope ?


[My Blog]
All roads lead to JavaRanch
Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
Yes I agree, as Christophe says, that an application-managed persistence contexts must be managed by the application(as its name says )

Additionally, when a JTA application-managed entity manager is used, if the entity manager is created outside the scope of the current JTA transaction, it is the responsibility of the application to associate the entity manager with the transaction (if desired) by calling EntityManager.joinTransaction.

For resource local transactions, the entity manager should start and commit the transaction by itself. Please see "5.7 Application-managed Persistence Contexts" of ejb-3_0-fr-spec-persistence.


Thanks and Regards
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Hi Jothi,

See the reply by Ralph to your thread "EntityManagerFactory vs EntityManager".

He has given a good explanation on this.

Regards,
Cham
 
Consider Paul's rocket mass heater.
 
subject: Doubt on PersistenceContext
 
Similar Threads
What is persistencecontext and EntityManager ?
Is annotations case-sensitive?
EM and Persistence Contexts
JNDI exception when creating dataSource
EJB with Hibernate