migrating JPA 2.2 to 3.0

created onOctober 5, 2023

changes

There are no new features in JPA 3.0. The changes in 3.0 just reflect the transition from Java EE to Jakarta EE by renaming the prefix of the JPA API packages, renaming the prefix of config vars in config files like persistence.xml and introducing the new Jakarta specific namespace for XML config files. Additionally, avoiding the use of the name Java avoids legal issues.

In detail, the changes are:

  • the prefix of all JPA API package names have been renamed from javax.persistence to jakarta.persistence.
  • the namespace of XML-based configuration has been changed from http://xmlns.jcp.org/xml/ns/persistence to https://jakarta.ee/xml/ns/persistence.
  • in configuration files, the properties prefix javax.persistence has been changed to jakarta.persistence for most of the properties, but not all of them. More on that in section migration.

migration

source and config files

Migration is for the most part just a matter of search and replace in your source code and config files:

  • in your *.java files, replace all imports of javax.persistence with jakarta.persistence
  • in the , replace the two instances of the namespace
    http://xmlns.jcp.org/xml/ns/persistence with https://jakarta.ee/xml/ns/persistence.
  • update the persistence version attribute in to 3.0. The version is in the opening tag, i.e.
  • check all JPA-related configuration files and replace instances of the config var prefix javax.persistence with jakarta.persistence. Take care when replacing the prefix, as some packages in Java SE are still in the javax.* namespace, as it is the case in javax.sql.

support of JPA spec implementation providers

Make sure you are using a JPA spec implementation that supports Jakarta Persistence 3.0. The following versions support Jakarta Persistence 3.0:

  • Eclipselink – version 3.0 and above. Version 3.0 supports Java 8 and 11. A better option is to use version 4.0 or 4.1 which support Java 11 and Java 17.
  • Hibernate – version 5.5 and above. All versions 5.x have reached their end-of-life. Versions 6.1 and 6.2 have also reached their end-of-life, so the best option is to migrate to version 6.3, which is compatible with Java 11, 17 and 21.

dependencies

Jakarta JPA 3.0 is included in the Jakarta EE 9 Web Profile. If you have the Jakarta EE 9 Web Profile API already included in your project, you don’t need the JPA 3.0 API.

gradle coordinates (kotlin):

compileOnly("jakarta.persistence:jakarta.persistence-api:3.0.0")

maven coordinates:

<dependency> <groupId>jakarta.persistence</groupId> <artifactId>jakarta.persistence-api</artifactId> <version>3.0</version> <scope>provided</scope> </dependency>

That’s it.

reference

Jakarta Persistence 3.0 Specification, Final Release, September 08, 2020

Java SE 21 & JDK 21, Module java.sql

Hibernate ORM Releases

EclipseLink 3.0 Release

EclipseLink 4.0 Release