Accessing data by using JPA inside of the bundle
About this task
Accessing data by using JPA inside of the bundle assumes that you are working in a bundle that is treated as a Java™ EE module on the server. For example, an OSGi web application bundle that has a JPA facet enabled and contains entities and the logic to access, consume, and display data by using JPA. Another example is a web project that contains JPA entities and the logic to consume data by using JPA that is published in an OSGi application rather than as part of an EAR deployment.
You need to configure your OSGi bundle and add the data sources to WebSphere® Application Server before you can access the JPA persistence units.
Ensure that your JPA persistence file contains references to a Java Transaction API (JTA) and non-JTA 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.