Spring Boot – package javax.persistence does not exist

We migrated the project to Spring Boot 3, and the JPA entity class hits package javax.persistence does not exist.


java: package javax.persistence does not exist

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;  

P.S. Tested with Spring Boot 3.1.2

Solution

Spring Boot 3 migrated all Java EE APIs javax.* to their equivalent Jakarta EE variant jakarta.* due to the transition from Oracle to the Eclipse Foundation.

To fix this, we should use the Jakarta Persistence (JPA) APIs under the jakarta.persistence package instead of javax.persistence.

Spring Boot 3 using Jakarta EE APIs jakarta.*


import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

Spring Boot 2.x using Java EE APIs javax.*


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;  

References

mkyong

Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities.

6 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Fran
2 years ago

Many thanks!

Lily
2 years ago

is jakarta.persistence.* not within spring-boot-starter-data-jpa ?
if not it is within which dependency?

Christina
1 year ago
Reply to  Lily

Good question! I have the same issue

Elias
2 years ago

Thanks teacher! you always help us.

pallavi
2 years ago

Thanks Its working your solutions

Raj
2 years ago

Thank you so much its working .