Consider the code below where Customer is an entity bean.
Assuming that "em" is a reference to the EntityManager with transaction-scoped persistence context, what is the state of the entity referenced by "cust" after the execution of statement 05?
Explanation: The "cust" entity becomes managed after the execution of statement 04. But at the end of the transaction in statement 05, all the entities associated with the persistence context becomes detached. Hence after the execution of statement 05, the "cust" variable references a detached entity.
Niranjan Deshpande wrote:the code above is using application managed entity manager and not a container managed entity manager.
Niranjan Deshpande wrote:3. From 2. above it's clear that 'Application Managed Entity Managers can be of either type: extended/transaction scoped!
JPA Specs wrote:The scope of the persistence context of an application-managed entity manager is extended. It is the responsibility of the application to manage the lifecycle of the persistence context.
Treimin Clark wrote:
But I feel it is wrong. Well, the question says that the Entity Manager is with transaction-scoped persistence context. If it is transaction-scoped, then the entity manager must be a container-managed entity manager. As container-managed entity managers always uses the JTA transactions, then this EntityManager's persistence context must be associated with a JTA transaction. In that case, em.getTransaction() method here, must throw IllegalStateException, because getTransaction() method cannot be invoked on a JTA EntityManager. Now, the entity is still in NEW state. Do you agree?