1
votes

I am using EJB 3.1 and I have a Stateless Session Bean that I am injecting an EntityManager into. One of the EJB's methods calls entityManager.setFlushMode(FlushModeType.COMMIT).

Two questions:

1) I assume that affects all EJBs that are part of this transaction. So for example if this SSB calls another method on another EJB which uses the REQUIRED transaction attribute and that EJB also injects an EntityManager then that entityManager used by that method will also be in a COMMIT flush mode. Is that true or do you have to explicitly set the flush mode in the method being called even if it is in the same TX?

2) Will setting the flushMode on the entity manager affect any other entity managers for the same PU injected into other EJBs but used in different transactions? I would assume not.

Thnx.

1

1 Answers

3
votes

Your assumptions are correct. Yes, setFlushMode on the injected EntityManager affects all EMs for the PU in the same transaction. No, it will not affect EMs in other transactions. See this answer: EJB 3.1 Transaction, EntityManager