As you know, transaction management is a cross-cutting issue. Therefore, it is not very good that your code is scattered modulo, where these problems are not their main task.
If you use the JTA UserTransaction in a non-EJB environment, then JTA is available (Apache Tomcat does not support JTA).
1 ° rule
Seam transaction management is enabled by default for all JSF requests (Seam 2.0 +).
I think that Seam transaction management sounds better like Seam-managed Transactions . This means that Sheim takes care, behind the scenes, to urge to begin and commit. Seam plays the role of a transaction manager using the Seam transaction manager
1 ° scenario : POJO + JTA is available (Apache Tomcat does not support JTA)
Transaction Manager used by Seam: org.jboss.seam.transaction.UTtransaction
Enabled by default in non-EJB (war) environments when JTA is available (JBoss JTA support)
If you are using a JPA EntityManager or Hibernate session, you need to register them to allow Seam to manage transaction boundaries
See 9.3. Seam-driven persistence contexts , how to set up a persistent persistence context (implemented using @In)
Then enter EntityManager (EntityManager) or Session (Hibernate) using @In (with ScopeType.CONVERSATION scope)
@Name("businessService") public class BusinessServiceImpl implementes BusinessService { @In private EntityManager entityManager; public void doSomething() { // You do not need to call entityManager().getTransaction().begin(); // because Seam Transaction Manager takes care of it // By using proxies // Therefore, if you call entityManager().getTransaction().begin() // You will get IllegalStateException // Some EntityManager operations persist, find etc // You do not need to call entityManager().getTransaction().commit(); // because Seam Transaction Manager takes care of it // By using proxies } }
Behind the scenes, the Seam Transaction Manager terminates the EntityManager (JPA) or session (Hibernate) in the active JTA UserTransaction by invoking the joinTransaction method
2 ° scenario : POJO + RESOURCE_LOCAL (either sleep mode or JPA) Transaction
Seam Transaction Manager (JPA): org.jboss.seam.transaction.EntityTransaction
Transaction Manager used by Seam (Hibernate): org.jboss.seam.transaction.HibernateTransaction
See 9.3. Seam-driven persistence contexts , how to set up a persistent persistence context (implemented using @In)
Behind the scenes, Seam Transaction Manager takes care of calling begin and commit in the underlying technology with proxies.
3 ° scenario : EJB
Transaction Manager used by Seam: org.jboss.seam.transaction.CMTTransaction
Enabled by default in an EJB environment. Take care, in this case, Seam does not control container-managed transactions.
Yours faithfully,