Accessing data using JPA in a different bundle
About this task
Tip:
Ensure that your JPA persistence file contains references to a Java™ Transaction API (JTA) and non-JTA data source.
JPA has two
transactional patterns for accessing a data source:
jta-data-source- The Java Transaction API (JTA) resource pattern depends on global transactions. The JTA resource pattern is typically used within the scope of an Enterprise JavaBeans (EJB) session facade. This configuration allows the session bean to control transaction and security contexts while JPA handles the persistence mappings. In this case, the application does not use the EntityTransaction interface but relies on the EntityManager enlisted with the global transaction when it is accessed.
non-jta-data-source- The non-JTA resource pattern is used to deal with a single resource in the absence of global transactions. The non-JTA resource pattern is typically used within the scope of a web application or an application client. The application controls the transaction with the data source with the EntityTransaction interface.
In persistence.xml files
for an OSGi application, the jta-data-source and non-jta-data-source elements access the data sources through
a Java Naming and Directory
Interface (JNDI) lookup, a JNDI lookup to the service registry, or
through Blueprint.
If the JTA and non-JTA data sources are not configured in the persistence.xml file, the default JTA and non-JTA data sources configured for the server are used. By default the values are null. Some JPA entity features require a non-JTA data source to be specified. For example, automatic entity identity generation.