About Question enthuware.oce-jpad.v6.2.594 :
Posted: Wed Jul 18, 2012 3:57 pm
In my opinion this answer is wrong. The correct one is:
"Container managed, transaction scoped EntityManager"
not:
"Container managed, transaction or extended scoped EntityManager"
Why:
It is stated that the injected object is EntityManager, NOT EntityManagerFactory. If container injects EntityManager in Servlet or SLSB it injects Transaction Scoped Persistence Context (most containers probably throws exception or injects null if @PersistenceContext(type=PersistenceContextType.EXTENDED) requsted in something other than SFSB. Because injection of EntityManager with declaration of Extended persistence context only works in SFSB. If the question will suggest that there will be injection of EntityManagerFactory - the servlet might use the creation of EntityManager in Application style:
EntityManager em = EntityManagerFactory.createEntityManager() which will return extended scoped entity manager.
thus the actual answer might be true, but will require restructuring the question.
The injection:
"@PersistenceContext(type=PersistenceContextType.EXTENDED|TRANSACTION)
EntityManager orderEM;"
only works in SFSB.
"Container managed, transaction scoped EntityManager"
not:
"Container managed, transaction or extended scoped EntityManager"
Why:
It is stated that the injected object is EntityManager, NOT EntityManagerFactory. If container injects EntityManager in Servlet or SLSB it injects Transaction Scoped Persistence Context (most containers probably throws exception or injects null if @PersistenceContext(type=PersistenceContextType.EXTENDED) requsted in something other than SFSB. Because injection of EntityManager with declaration of Extended persistence context only works in SFSB. If the question will suggest that there will be injection of EntityManagerFactory - the servlet might use the creation of EntityManager in Application style:
EntityManager em = EntityManagerFactory.createEntityManager() which will return extended scoped entity manager.
thus the actual answer might be true, but will require restructuring the question.
The injection:
"@PersistenceContext(type=PersistenceContextType.EXTENDED|TRANSACTION)
EntityManager orderEM;"
only works in SFSB.