Maaz Zindani

Loading the index…

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

Spring Boot cannot build its EntityManagerFactory proxy around Hibernate's SessionFactory

Your error

java.lang.IllegalStateException: EntityManagerFactory interface [interface org.hibernate.SessionFactory] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the 'entityManagerFactoryInterface' property to plain [jakarta.persistence.EntityManagerFactory]1 more line it can show

Fix it fast

Most common cause, 1 of 3

The build raises the JPA API to 3.2 on a Boot 3 project

Delete the override and let Boot choose the JPA API.

Fix
<!-- pom.xml: remove these lines -->
<properties>
  <jakarta-persistence.version>3.2.0</jakarta-persistence.version>
</properties>
<dependency>
  <groupId>jakarta.persistence</groupId>
  <artifactId>jakarta.persistence-api</artifactId>
  <version>3.2.0</version>
</dependency>
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

EntityManagerFactory interface [org.hibernate.SessionFactory] seems to conflict with Spring's EntityManagerFactoryInfo mixin appears when jakarta.persistence-api 3.2 sits next to Hibernate 6: both declare getSchemaManager() with different return types. On Spring Boot 3.x keep the managed JPA 3.1.0; if you need JPA 3.2, move to Boot 4.x, which pairs it with Hibernate 7.4.

  • Applies to Spring Boot 3.5.12 (Hibernate 6.6.44, JPA 3.1.0), Spring Boot 4.2.0 (Hibernate 7.4.15, JPA 3.2.0), Gradle 9.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the versions of the JPA API jar and of hibernate-core that the app really runs with. Hibernate 6 with jakarta.persistence-api 3.2 is the broken pair; the next question is only how 3.2 got in.

Run this first
# Maven
mvn dependency:tree -Dincludes=jakarta.persistence
mvn dependency:tree -Dincludes=org.hibernate.orm
# Gradle
./gradlew -q dependencyInsight --dependency jakarta.persistence-api --configuration runtimeClasspath

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

  1. 1The build raises the JPA API to 3.2 on a Boot 3 projectpom.xml or build.gradle sets jakarta-persistence.version, or declares jakarta.persistence-api with its own version, and the tree shows 3.2.x beside hibernate-core 6.x
  2. 2A library pulls in JPA 3.2 and Gradle's platform lets it winYour build has no JPA override, the project imports the Boot BOM with platform(), and dependencyInsight names another library as the one that requested 3.2
  3. 3A plain Spring project without the Boot BOM picks up 3.2 by nearest definitionThere is no Spring Boot parent or BOM, and the Maven tree reaches jakarta.persistence-api 3.2 through a library that is closer to your project than hibernate-core

What does the error look like?

  • java.lang.IllegalStateException: EntityManagerFactory interface [interface org.hibernate.SessionFactory] seems to conflict with Spring's EntityManagerFactoryInfo mixin - consider resetting the 'entityManagerFactoryInterface' property to plain [jakarta.persistence.EntityManagerFactory]
  • Caused by: java.lang.IllegalArgumentException: methods with same signature getSchemaManager() but incompatible return types: [interface org.hibernate.relational.SchemaManager, interface jakarta.persistence.SchemaManager]

Cause 1 of 3

The build raises the JPA API to 3.2 on a Boot 3 project

You seepom.xml or build.gradle sets jakarta-persistence.version, or declares jakarta.persistence-api with its own version, and the tree shows 3.2.x beside hibernate-core 6.x

Check

Boot 3.5.12 manages JPA 3.1.0 with Hibernate 6.6.44. When the build forces the 3.2 API, Spring tries to create a proxy that implements both Hibernate's SessionFactory and JPA's EntityManagerFactory, and the two getSchemaManager() methods cannot live in one proxy. In the Boot issue, a Spring Framework maintainer traced the clash to Hibernate's own interface, so resetting entityManagerFactoryInterface as the message suggests only moves the failure further down.

Check
grep -nE "jakarta-persistence.version|jakarta.persistence-api" pom.xml build.gradle

Fix

Delete the override and let Boot choose the JPA API. If your code truly needs JPA 3.2, upgrade to Boot 4.x instead, where the managed Hibernate is a 7.x release built for that API.

Fix
<!-- pom.xml: remove these lines -->
<properties>
  <jakarta-persistence.version>3.2.0</jakarta-persistence.version>
</properties>
<dependency>
  <groupId>jakarta.persistence</groupId>
  <artifactId>jakarta.persistence-api</artifactId>
  <version>3.2.0</version>
</dependency>

Verify

The tree shows jakarta.persistence-api 3.1.0 on Boot 3.5, the application context starts, and repositories load.

Verify
mvn dependency:tree -Dincludes=jakarta.persistence

Confirmed by github.com

Did this fix it?

Cause 2 of 3

A library pulls in JPA 3.2 and Gradle's platform lets it win

You seeYour build has no JPA override, the project imports the Boot BOM with platform(), and dependencyInsight names another library as the one that requested 3.2

Check

With Gradle's own BOM support, a platform dependency only recommends versions. Any other request in the graph can lift jakarta.persistence-api above the 3.1.0 that Boot 3.5 expects, and Boot's version properties have no effect in that setup.

Check
./gradlew -q dependencyInsight --dependency jakarta.persistence-api --configuration runtimeClasspath

Fix

Make Boot's versions binding with enforcedPlatform, or pin the group with a resolution strategy as Boot's Gradle guide shows. If the library cannot run on JPA 3.1, choose its previous release or move the app to Boot 4.x.

Fix
dependencies {
    implementation enforcedPlatform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}

// or pin only the JPA API group
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'jakarta.persistence') {
            details.useVersion '3.1.0'
        }
    }
}

Verify

dependencyInsight reports 3.1.0 as the selected version, and bootRun reaches the started message.

Verify
./gradlew bootRun

Confirmed by docs.spring.io

Did this fix it?

Cause 3 of 3

A plain Spring project without the Boot BOM picks up 3.2 by nearest definition

You seeThere is no Spring Boot parent or BOM, and the Maven tree reaches jakarta.persistence-api 3.2 through a library that is closer to your project than hibernate-core

Check

Maven keeps the version found nearest to your project in the dependency tree. A library declared directly can therefore drag in the newer JPA API ahead of the one hibernate-core 6 was built for. Hibernate's releases page lists the 6.x series with Jakarta Persistence 3.1 and 7.0 with 3.2.

Check
mvn dependency:tree -Dverbose -Dincludes=jakarta.persistence

Fix

Pin the API in your own dependencyManagement block. Maven applies that version to transitive copies as well, which overrides the nearest-definition choice.

Fix
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>jakarta.persistence</groupId>
      <artifactId>jakarta.persistence-api</artifactId>
      <version>3.1.0</version>
    </dependency>
  </dependencies>
</dependencyManagement>

Verify

A single jakarta.persistence-api 3.1.0 is left in the tree and the LocalContainerEntityManagerFactoryBean initialises.

Verify
mvn dependency:tree -Dincludes=jakarta.persistence

Confirmed by maven.apache.org

Did this fix it?

How do I stop it coming back?

  • Treat jakarta.persistence-api and hibernate-core as one pair: change both only through a Boot version bump.
  • Run dependencyInsight for jakarta.persistence-api in CI after adding any persistence-related library, and fail if it reports a different version than Boot manages.
  • Check Hibernate's releases page before an upgrade; each series lists the Jakarta Persistence version it implements.

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: QistLock, Dispatch Pro, Nuclear Home Video.

Next step

Want this handled for good?

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