Spring cannot load jakarta.persistence.spi.PersistenceProvider at runtime
Your error
java.lang.NoClassDefFoundError: jakarta/persistence/spi/PersistenceProviderFix it fast
Most common cause, 1 of 2hibernate-core is pinned to a 5.x release that only knows javax.persistence
Delete the hand-written Hibernate dependency and use the JPA starter, which brings hibernate-core from org.hibernate.orm and the Jakarta API jar at the versions Boot manages.
<!-- remove: org.hibernate:hibernate-core with a 5.x version -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>Short answer
java.lang.NoClassDefFoundError: jakarta/persistence/spi/PersistenceProvider means Spring's JPA classes (Spring Framework 6 and 7) found no Jakarta Persistence API jar at runtime. Usually hibernate-core is pinned to a 5.x release, which brings javax.persistence instead, or jakarta.persistence-api is scoped provided on Tomcat. Let Spring Boot manage org.hibernate.orm:hibernate-core and package the API jar.
Which cause do you have?
List every persistence API and Hibernate artifact Maven resolves, with its scope. Which package you see (javax or jakarta), the Hibernate group and the scope column each point to a different cause.
mvn dependency:tree -Dincludes=jakarta.persistence,javax.persistence,org.hibernate,org.hibernate.ormThen find the line you see in this list and open its fix:
- 1hibernate-core is pinned to a 5.x release that only knows javax.persistence
The tree shows org.hibernate:hibernate-core 5.x with javax.persistence-api 2.2 and no jakarta.persistence-api line at all - 2jakarta.persistence-api is scoped provided, but Tomcat does not ship JPA
The tree shows jakarta.persistence-api with scope provided, the code compiles, and the error appears only after the WAR is deployed
What does the error look like?
java.lang.NoClassDefFoundError: jakarta/persistence/spi/PersistenceProvider
Cause 1 of 2
hibernate-core is pinned to a 5.x release that only knows javax.persistence
You seeThe tree shows org.hibernate:hibernate-core 5.x with javax.persistence-api 2.2 and no jakarta.persistence-api line at all
Check
The PersistenceProvider class cannot be found because Hibernate 5 was built for the old Java EE package names. Hibernate 6.0 moved from javax.persistence to jakarta.persistence, and Spring Boot 3 switched its JPA starter to the new org.hibernate.orm group ID. A dependency still declared as org.hibernate:hibernate-core with an explicit 5.x version escapes Boot's version management.
grep -n -B2 -A3 "<artifactId>hibernate-core</artifactId>" pom.xmlFix
Delete the hand-written Hibernate dependency and use the JPA starter, which brings hibernate-core from org.hibernate.orm and the Jakarta API jar at the versions Boot manages. Your entity imports must use jakarta.persistence as well.
<!-- remove: org.hibernate:hibernate-core with a 5.x version -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>Verify
The tree now lists org.hibernate.orm:hibernate-core 7.4.15.Final and jakarta.persistence:jakarta.persistence-api 3.2.0, and the app starts.
mvn dependency:tree -Dincludes=jakarta.persistence,org.hibernate.ormConfirmed by github.com
Cause 2 of 2
jakarta.persistence-api is scoped provided, but Tomcat does not ship JPA
You seeThe tree shows jakarta.persistence-api with scope provided, the code compiles, and the error appears only after the WAR is deployed
Check
Maven's provided scope means you expect the JDK or a container to hand over the jar at runtime, so it is left out of WEB-INF/lib. Tomcat implements only a subset of Jakarta EE; its version table lists Servlet, Pages, EL, WebSocket, Authentication, Annotation and one debugging spec. Persistence is not among them, so nothing supplies the class once the app runs there.
unzip -l target/*.war | grep -i persistenceFix
Drop the provided scope from jakarta.persistence-api, or remove the explicit entry and let hibernate-core bring the API in at compile scope. Keep provided only for APIs your server really implements, such as the Servlet API on Tomcat.
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<!-- no <scope>provided</scope> when the server is Tomcat -->
</dependency>Verify
The rebuilt WAR lists a jakarta.persistence-api jar under WEB-INF/lib, and the context starts on Tomcat 11.0.29.
mvn -q clean package && unzip -l target/*.war | grep jakarta.persistence-apiConfirmed by tomcat.apache.org
How do I stop it coming back?
- Never give hibernate-core or jakarta.persistence-api a version of your own in a Spring Boot build; the Boot parent or BOM already picks a matching pair.
- Add a CI step that fails when dependency:tree prints javax.persistence or org.hibernate:hibernate-core, so an old pin cannot slip back in.
- When a pom.xml template comes from a full application server project, review each provided scope before deploying to Tomcat.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Dispatch Pro.