Persistence unit as RESOURCE_LOCAL or JTA?

cometta picture cometta · Dec 26, 2009 · Viewed 62.6k times · Source

I have queries as below:

  1. What is the difference of these two?
  2. Are both of these supported by all databases?
  3. Are JPA TransactionManager and JTA TransactionManager different?

Answer

skaffman picture skaffman · Dec 26, 2009

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 units (or other databases), then RESOURCE_LOCAL may not be good enough.

JTA is also used for managing transactions across systems like JMS and JCA, but that's fairly exotic usage for most of us.

To use JTA, you need support for it in your application server, and also support from the JDBC driver.