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?
[A] new
[B] managed
[C] detached
[D] remove
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.
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Niranjan Deshpande wrote:the code above is using application managed entity manager and not a container managed entity manager.
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
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?
SCJP 5 (98%) - SCBCD 5 (98%)
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
SCJP 5 (98%) - SCBCD 5 (98%)
Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1