In Java Persistence API (JPA), the persistence.xml
file is used to configure the persistence unit for your application. The transaction-type
attribute in the persistence.xml
file specifies the type of transaction management that your application will use. There are two possible values for the transaction-type
attribute:
JTA
(Java Transaction API):
transaction-type
is set to JTA
, the application relies on the container to handle transactions using Java EE's transaction management capabilities.Example persistence.xml
configuration with transaction-type
set to JTA
:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="myPersistenceUnit" transaction-type="JTA"> <!-- Other configuration settings --> </persistence-unit> </persistence>
RESOURCE_LOCAL
:
transaction-type
is set to RESOURCE_LOCAL
, your application is responsible for managing transactions using JPA's EntityManager
and EntityTransaction
APIs.Example persistence.xml
configuration with transaction-type
set to RESOURCE_LOCAL
:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"> <persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL"> <!-- Other configuration settings --> </persistence-unit> </persistence>
The choice between JTA
and RESOURCE_LOCAL
depends on your application's environment and requirements. In a Java EE application, you would typically use JTA
and rely on the container for transaction management. In a Java SE application or if you need fine-grained control over transactions, you would use RESOURCE_LOCAL
.
Make sure to configure the persistence.xml
file according to your application's needs and the transaction management approach you plan to use.
android-tabs draw gyp partial electron-builder backup laravel-5.7 openpgp appcompatactivity imagebutton