Page 1 of 1

About Question enthuware.oce-jpad.v6.2.374 :

Posted: Sat Dec 24, 2016 5:00 pm
by johnlong
Transaction management type of a session bean and type of entity manager (container managed or bean managed) are two different things. Any type of entity manager can be enlisted in a transaction started by a session bean with bean managed transactions.
Does it mean that if session bean is annotated @TransactionManagement(CONTAINER) we still can inject EntityManager (or EntityManagerFactory with @PersistenceUnit) with @PersistentContext and get application-managed transactions?

If yes, how shall we get transaction instance or proxy : from EJBContext.getUserTransaction(), get it injected with @Resource or @Inject annotations?
Or it means that we can only "manage" entity manager, but we do not control transaction and transaction-management is still done by container?

Re: About Question enthuware.oce-jpad.v6.2.374 :

Posted: Sun Dec 25, 2016 12:31 pm
by admin
No, it doesn't mean that. What it means is that if one bean (A) calls another bean (B), then the choice of type of EntityManager for bean B is not affected by the fact that the transaction was started by a bean with bean managed transactions.
IOW, it does not matter how to start a transaction in a bean. It does not affect the type of EntityManager of another bean.

Re: About Question enthuware.oce-jpad.v6.2.374 :

Posted: Sun Dec 25, 2016 6:57 pm
by johnlong
Clear, thanks.

Re: About Question enthuware.oce-jpad.v6.2.374 :

Posted: Sun Apr 09, 2017 11:24 am
by unvector
Lets take into consideration option 1.
Could we also inject two entity managers (instead of two datasources as in the example) from distinct persistent units and synchronize them with single bean-managed transaction started by UserTransaction?

Re: About Question enthuware.oce-jpad.v6.2.374 :

Posted: Sun Apr 09, 2017 9:16 pm
by admin
Yes, that can be done.