• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

EntityManager types in JPA

 
Ranch Hand
Posts: 10191
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Joe Harry
Ranch Hand
Posts: 10191
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 18
Mac Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 115
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!