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.