Main Tutorials

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

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
4 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Fran
3 months ago

Many thanks!

Lily
3 days ago

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

pallavi
2 months ago

Thanks Its working your solutions

Raj
3 months ago

Thank you so much its working .