Blog JPA

Transitioning from Java Persistence API (JPA) to Jakarta Persistence: A Comprehensive Guide

What is Jakarta Persistence?

This is because the Java Persistence API (JPA) was renamed to Jakarta Persistence in 2019¹. The change was made after Java EE was open-sourced by Oracle and the rights were given to the Eclipse Foundation¹. They were legally required to change the name from Java as Oracle has the rights over the Java brand¹.

So, the package javax.persistence was replaced by jakarta.persistence¹³. This means that if you’re using a newer version of Hibernate or Spring Data JPA, you’ll need to use the jakarta.persistence classes instead of the javax.persistence classes¹³.

For example, if you’re using Spring Boot 3/Spring Framework 6, they have upgraded to Jakarta EE 9+, hence the corresponding version of Spring Data JPA is now on the “jakarta” versions of things¹. Spring Boot 2.7 and earlier are still on “javax” versions of things¹.

So, if you’re seeing import jakarta.persistence.Entity; instead of import javax.persistence.*;, it’s because you’re using a newer version of the library that has made the switch to Jakarta Persistence¹³.

I hope this helps! Let me know if you have any other questions. 😊

Source: Conversation with Copilot, 29/5/2024
(1) java – Why has javax.persistence-api been replaced by jakarta …. https://stackoverflow.com/questions/60021815/why-has-javax-persistence-api-been-replaced-by-jakarta-persistence-api-in-spring.
(2) Bootstrapping EntityManager in Hibernate – HowToDoInJava. https://howtodoinjava.com/hibernate/bootstrap-hibernate-entitymanager/.
(3) Jakarta Persistence – Wikipedia. https://en.wikipedia.org/wiki/Jakarta_Persistence.
(4) Hibernate5/javax.persistence vs Hibernate6/jakarta.persistence. https://stackoverflow.com/questions/72286680/hibernate5-javax-persistence-vs-hibernate6-jakarta-persistence.

The Java Persistence API (JPA) has been a cornerstone of Java enterprise development for many years, providing a standard API for object-relational mapping (ORM). However, in 2019, a significant change occurred: JPA was renamed to Jakarta Persistence, and the package was changed from javax.persistence to jakarta.persistence.

Why the Change?

The change was part of the transition from Java EE to Jakarta EE. When Oracle open-sourced Java EE and transferred its rights to the Eclipse Foundation, they were legally required to change the name from Java, as Oracle owns the rights to the Java brand. As a result, the community chose the new name, Jakarta.

Impact of the Change

Starting from Hibernate version 6.0.0.Final, Hibernate moved from Java Persistence to Jakarta Persistence as defined by the Jakarta EE spec. This means developers need to use the Jakarta Persistence classes (jakarta.persistence.*) instead of the Java Persistence classes (javax.persistence.*).

Spring Boot 3/Spring Framework 6 have also upgraded to Jakarta EE 9+, hence the corresponding version of Spring Data JPA is now on the “jakarta” versions of things. Spring Boot 2.7 and earlier are still on “javax” versions of things.

Maven Dependencies

To use Jakarta Persistence in your Maven project, you need to add the following dependency to your pom.xml file:

XML
Avatar

Neelabh

About Author

As Neelabh Singh, I am a Senior Software Engineer with 6.6 years of experience, specializing in Java technologies, Microservices, AWS, Algorithms, and Data Structures. I am also a technology blogger and an active participant in several online coding communities.

You may also like

Blog Design Pattern

Understanding the Builder Design Pattern in Java | Creational Design Patterns | CodeTechSummit

Overview The Builder design pattern is a creational pattern used to construct a complex object step by step. It separates
Blog Tech Toolkit

Base64 Decode

Base64 encoding is a technique used to encode binary data into ASCII characters, making it easier to transmit data over