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

6 comments on “Spring Boot – package javax.persistence does not exist

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

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *