Java Persistence API 2.1 behavior changes
If you already use the jpa-2.0
feature for your applications, continue
using the jpa-2.0
feature for your existing applications to avoid any migration
issues. For new applications, it is best to use the jpa-2.1
feature, which enables
you to take advantage of the new features that are available in the JPA 2.1 specification. If you
want to change your existing applications to use the jpa-2.1
feature instead of the
jpa-2.0
feature, you might need to adjust your application in the migration
process.
Differences between jpa-2.0
and jpa-2.1
Be aware of a few major differences between the jpa-2.0
and
jpa-2.1
features. See the following:
- PersistenceProvider class name differences
jpa-2.0
- IBM®
provider:
com.ibm.websphere.persistence.PersistenceProviderImpl
- OpenJPA provider:
org.apache.openjpa.persistence.PersistenceProviderImpl
- IBM®
provider:
- Caching behavior differences
-
jpa-2.0
: Caching is disabled by default. If your application needs to take advantage of a L2 cache, you must explicitly enable it. - Enhancement / weaving differences
-
jpa-2.0
: OpenJPA requires entities to be enhanced. For more information, see Enhancement of JPA entities for JPA 2.0 in the product documentation.
- Data source usage differences
-
The
jpa-2.0
feature sparingly uses the non-jta-datasource, so few non-jta-datasource connections are required when you are tuning an application.
JPA 2.1 features available in OpenJPA
OpenJPA, the JPA 2.0 provider, has features that function similarly to the new JPA 2.1 features.
This means that if you have an existing application that uses the jpa-2.0
feature
and want to use some of the JPA 2.1 features, you do not have to switch to the
jpa-2.1
feature. Instead, you can use the equivalent of the new feature that is
provided by OpenJPA. Some of the key JPA 2.1 features that are available in OpenJPA are:
- Schema Generation
-
With this feature, you can generate DDL or interact directly with the database to define table schemas based on JPA entity definition. For more information, refer to section 9.4 of the JPA 2.1 Specification.
OpenJPA equivalent feature: Schema Mapper
- Entity Graphs
-
With this feature, you can specify fetching or processing of a graph of entity objects. For more information, refer to section 3.7 of the JPA 2.1 Specification.
OpenJPA equivalent feature: FetchPlan and FetchGroup
- Stored Procedure Queries
-
With this feature, you can invoke procedures that are stored in databases. For more information, refer to section 3.10.17 of the JPA 2.1 Specification.
OpenJPA equivalent feature: Query invocation
- Basic Attribute Type conversion
-
With this feature, you can convert between an attribute entity representation and database representation for basic type attributes. For more information, refer to section 3.8 of the JPA 2.1 Specification.
OpenJPA equivalent feature: Externalizer feature
- @Index and @ForeignKey annotations
-
Refer to sections 11.1.19 and 11.1.23 of the JPA 2.1 Specification.
OpenJPA equivalent feature: OpenJPA's @Index and @ForeignKey.
- Unwrap utility methods for EntityManager, Cache
-
Refer to sections 3.1.1 and 7.10 of the JPA 2.1 Specification.
OpenJPA equivalent features: EntityManagerImpl.unwrap() and OpenJPAPersistence.cast().
- Object construction when mapping results from native SQL
-
Refer to Section 3.10.16.2.2 of the JPA 2.1 Specification.
OpenJPA equivalent feature: ResultShape object.