How to use JTA support in Tomcat 6 for Hibernate?

If you want JTA support in Tomcat you’ll need to use a standalone transaction manager like Atomikos, JOTM, Bitronix, SimpleJTA, JBossTS or GeronimoTM/Jencks. But honestly, if you’re not going to handle transactions across multiple resources, then you can live without JTA (and if you really need JTA, use a full blown application server).

Difference between a “jta-datasource” and a ” resource-local ” datasource?

The terms “jta-datasource” and “resouce-local datasource” are a little vague to me. I guess you actually refer to the jta-datasource and non-jta-datasource elements. In short: if the transaction type of the persistence unit is JTA, the jta-datasource element is used to declare the JNDI name of the JTA data source that will be used to … Read more

javax.transaction.Transactional vs org.springframework.transaction.annotation.Transactional

Spring has defined its own Transactional annotation to make Spring bean methods transactional, years ago. Java EE 7 has finally done the same thing and now allows CDI bean methods to be transactional, in addition to EJB methods. So since Java EE 7, it also defines its own Transactional annotation (it obviously can’t reuse the … Read more

persistence.xml different transaction-type attributes

Defaults Default to JTA in a JavaEE environment and to RESOURCE_LOCAL in a JavaSE environment. RESOURCE_LOCAL With <persistence-unit transaction-type=”RESOURCE_LOCAL”> you are responsible for EntityManager (PersistenceContext/Cache) creating and tracking You must use the EntityManagerFactory to get an EntityManager The resulting EntityManager instance is a PersistenceContext/Cache An EntityManagerFactory can be injected via the @PersistenceUnit annotation only (not … Read more

Persistence unit as RESOURCE_LOCAL or JTA?

JPA implementations have the choice of managing transactions themselves (RESOURCE_LOCAL), or having them managed by the application server’s JTA implementation. In most cases, RESOURCE_LOCAL is fine. This would use basic JDBC-level transactions. The downside is that the transaction is local to the JPA persistence unit, so if you want a transaction that spans multiple persistence … Read more