javajpajakarta-eejtapersistence.xml

persistence.xml different transaction-type attributes


In the persistence.xml JPA configuration file, you can have a line like:

<persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type="JTA">

or sometimes:

<persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type=”RESOURCE_LOCAL”>

My question is:

What is the difference between transaction-type="JTA" and transaction-type=”RESOURCE_LOCAL” ?

I also noticed some persistence.xml files with the transaction-type missing. Is it correct?


Solution

  • 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

    JTA

    With <persistence-unit transaction-type="JTA"> the container will do EntityManager (PersistenceContext/Cache) creating and tracking.