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

Moderator: admin

Post Reply
johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

johnlong
Posts: 197
Joined: Mon Jun 20, 2016 5:06 pm
Contact:

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

Post by johnlong »

Clear, thanks.

unvector
Posts: 18
Joined: Sun Jun 21, 2015 2:56 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, that can be done.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 47 guests