| Forums: |
java EJB SCBCD
OCEJPA
|
| Author |
EntityManager types in JPA
|
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
Guys,
The Pro EJB 3 book dictates on page 112 that the JPA defines no less than 3 different types of EntityManager. I can see only two of them, namely the Container Managed Entity Manager and the Application Managed Entity Manager. Which is the third one? Or is that simply a typo from the book?
|
SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
Witold Koszulinski
Greenhorn
Joined: Aug 12, 2007
Posts: 3
|
|
Hi Jothi,
There are two container-managed entity managers. The first one is transaction-scoped entity manager and the second one is extended entity manager. Both described on page 112 and on page 113. There is also application-managed entity manager described on page 117.
Regards
Witold
|
SCJP 5, SCWCD 5, SCBCD 5
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
|
The extended and transaction scoped are subtypes for the Container Managed Entity Manager. But what about Application Managed Entity Manager. Can't they also be transaction scoped or extended scoped? Correct me if I'm wrong!
|
 |
Uppala Ramana
Greenhorn
Joined: Jan 14, 2010
Posts: 14
|
|
The extended and transaction scoped are subtypes for the Container Managed Entity Manager. But what about Application Managed Entity Manager. Can't they also be transaction scoped or extended scoped? Correct me if I'm wrong
Hi Jothi,
There are two ways of using the EntityManager
1) Container Managed ::: Using Dependency Injection ...so the container is responsible for initializing the EntityManager
@PersistenceContext
EntityManager entityManager;
2) Application Managed::: User or Application is Responsible for creating and initializing the EntityManager
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyUnit")
EntityManager em = emf.createEntityManager();
Now coming back to Transaction or Extended ..those are the Persistence Context Types.
Container Managed Entity Manager can have any of the below Persistent Context Type
@PersistenceContext(type=PersistenceContextType.TRANSACTION)
EntityManager entityManager;
@PersistenceContext(type=PersistenceContextType.EXTENDED)
EntityManager em;
As far as i know, for the Application Managed Entity Manager ..application is responsible for managing the transactions.
But what about Application Managed Entity Manager. Can't they also be transaction scoped or extended scoped? Correct me if I'm wrong!
That dependes on the application code...i think there is no meaning of extended scope for the application managed entity manager.
|
Ramana Uppala
SCJA,SCJP
|
 |
Logan Lee
Greenhorn
Joined: Oct 28, 2009
Posts: 18
|
|
But what about Application Managed Entity Manager. Can't they also be transaction scoped or extended scoped? Correct me if I'm wrong!
Only container managed contexts can be transaction-scoped, so only Entity Managers that are injected with the @PersistenceContext annotation or it's XML equivalent may be transaction-scoped.
|
 |
Singh Harmeet
Ranch Hand
Joined: Aug 05, 2011
Posts: 114
|
|
Uppala Ramana explain the three types of JPA transaction . but
and
are the same , because by default default value is so , how we said that there is three type of JPA entity managers.
|
With Regards :-
Harmeet Singh
|
 |
 |
|
|
subject: EntityManager types in JPA
|
|
|