The following two types of EntityManager are available depending on how the transactions are controlled:
The following table describes the relationship between the types of EntityManager and the transaction control methods.
Table 5-6 Relationship between types of EntityManager and transaction control methods
Types of EntityManager | Transaction control method | |
---|---|---|
JTA | Resource local | |
Container-managed EntityManager | Y#1 | N |
Application-managed EntityManager #2 | Y | Y |
#1 The transaction is necessarily controlled by the JTA.
#2 You can select whether to control the transaction using the JTA or whether the application controls the transaction, by explicitly using the EntityTransaction API. When the EntityTransaction API is used, the transaction becomes a resource local transaction. Even if the JTA transaction exists, the transaction is controlled regardless of the JTA transaction.
You specify whether you want to use the JTA entity manager or the resource local entity manager in the definition of the persistence unit. For details on how to specify definitions in the persistence unit, see 5.8.1(2) transaction-type attribute.