Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Spring cannot load jakarta.persistence.spi.PersistenceProvider at runtime

Your error

java.lang.NoClassDefFoundError: jakarta/persistence/spi/PersistenceProvider

Fix it fast

Most common cause, 1 of 2

hibernate-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.

Fix
<!-- remove: org.hibernate:hibernate-core with a 5.x version -->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to Spring Boot 4.2.0 (Hibernate 7.4.15.Final, jakarta.persistence-api 3.2.0), Spring Framework 7.1.0, Apache Tomcat 11.0.29, maven-dependency-plugin 3.11.0
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
mvn dependency:tree -Dincludes=jakarta.persistence,javax.persistence,org.hibernate,org.hibernate.orm

Then find the line you see in this list and open its fix:

  1. 1hibernate-core is pinned to a 5.x release that only knows javax.persistenceThe tree shows org.hibernate:hibernate-core 5.x with javax.persistence-api 2.2 and no jakarta.persistence-api line at all
  2. 2jakarta.persistence-api is scoped provided, but Tomcat does not ship JPAThe 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.

Check
grep -n -B2 -A3 "<artifactId>hibernate-core</artifactId>" pom.xml

Fix

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.

Fix
<!-- 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.

Verify
mvn dependency:tree -Dincludes=jakarta.persistence,org.hibernate.orm

Confirmed by github.com

Did this fix it?

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.

Check
unzip -l target/*.war | grep -i persistence

Fix

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.

Fix
<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.

Verify
mvn -q clean package && unzip -l target/*.war | grep jakarta.persistence-api

Confirmed by tomcat.apache.org

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.