Guys,
I'm very comfused about some concepts. I've listed them below and I would like to know whether everything I state is correct. There are also a few questions listed. I would really appreciate your inputs!
CONTAINER-MANAGED TRANSACTION-SCOPED ENTITYMANAGER
- Uses JTA for transaction management (single or extended)
- Created with @PersistenceContext(type=TRANSACTIONAL/EXTENDED)
- The transactional persistence context begins when the EntityManager is invoked in the scope of an active JTA transaction, and there is no persistence context currently associated with the transaction
- The transactional persistence context ends when the JTA transaction commits or rolls back (so entities become detached)
- When there is no transaction available, a new temporary persistence context will be created upon a method invocation (e.g. entityManager.find())
- An extended persistence context can only be used in stateful beans. The extended persistence context exists from the point a stateful bean declared an EntityManager. The extended persistence context is maintained during the entire lifecycle of the bean. This means that all returned entities are always in an attached (managed) state.
- An extended persistence context is closed when the @Remove annotated method has ended
APPLICATION-MANAGED TRANSACTION-SCOPED ENTITYMANAGER
- Uses JTA for transaction management (always extended, so single is not possible??)
- Created with @PersistenceUnit
APPLICATION-MANAGED RESOURCE-LOCAL ENTITYMANAGER
- Uses EntityTransaction for transaction management
- Created with @PersistenceUnit
COMMON PROPERTIES FOR APPLICATON-MANAGED ENTITYMANAGERS
- All application-managed persistence contexted are extended in scope, and therefore may span multiple transactions. An extended persistence context exists from the moment the EntityManager is created and ends when entityManager.close() is called.
-
You should call entityManager.close() when you want to release the peristence context. After you've invoked this method, you can only call isOpen() and getTransaction() or you will get an
IllegalStateException. If entityManger.close() within an active transaction, the persistence context will remain managed until the transaction completes.
- An extended persistence context obtained from an application-managed EntityManager is a stand-alone persistence context; it will never be propagated.
- When a JTA application-managed EntityManager is used, if the EntityManager is created outside the scope of the current JTA transaction, it is the responsiblity of the application to associate the EntityManager with the transaction by calling entityManager.joinTransaction().
USERTRANSACTION
- Only to be used in session beans (or MDB's) with BMT.
- When to use EntityTransaction of UserTransaction? When a bean is CMT, we should use EntityTransaction and when it's BMT, we should use UserTransaction. Is this statement correct??