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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Obtaining a PersistenceContext in Java EE" Watch "Obtaining a PersistenceContext in Java EE" New topic

Obtaining a PersistenceContext in Java EE

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345


What is the deal with obtaining a PersistenceContext using @PersistencContext annotation and what difference or a performance overhead it is when I say the following,

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!
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
the first one is managed by the application and the second one by container.

So you can conclude the container managed persistence context is more efficient in it's operation's.

SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog-
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345

But even in the line,

it is the contaner that performs the DI. So dosn't that mean that it is managed by the container?
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
In this case the entity manager factory is managed by the container, but not the entity manager itself.

As a remark concerning performance aspects: I was once told on glassfish forum that creating an entity manager is a lightweight operation.

SCJP 5 (98%) - SCBCD 5 (98%)
I agree. Here's the link:
subject: Obtaining a PersistenceContext in Java EE
Similar Threads
Difference between usage of PersistenceContext and PersistenceUnit ?
How to work with multiple persistence units
JPA2.0 CascadeType.ALL doesn't cascade persist
JTA Transaction on Stateful Session Bean.
JBoss 5.1.0 GA + EJB 3.0: RESTful Web Services with Jersey