Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Class org.hibernate.internal.SessionImpl does not implement the requested interface jakarta.persistence.EntityManager #952

Closed
anil-subudhi opened this issue Jan 21, 2025 · 5 comments

Comments

@anil-subudhi
Copy link

anil-subudhi commented Jan 21, 2025

Hibernate dependencies:

grails-datastore-gorm-hibernate5-9.0.0-M2.jar
hibernate-commons-annotations-5.1.2.Final.jar
hibernate-core-5.6.15.Final.jar
hibernate-core-jakarta-5.6.15.Final.jar
hibernate-ehcache-5.6.15.Final.jar
hibernate-validator-8.0.2.Final.jar
hibernate5-9.0.0-M2.jar

Dependency tree of hibernate-echache

|    +--- org.hibernate:hibernate-ehcache:5.6.15.Final
|    |    +--- org.jboss.logging:jboss-logging:3.4.3.Final -> 3.6.1.Final
|    |    +--- org.hibernate:hibernate-core:5.6.15.Final

org.hibernate.internal.SessionImpl present in hibernate-core 5.6.15.Final doesn't implement jakarta.persistence.EntityManager
https://github.com/hibernate/hibernate-orm/blob/5.6/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Error:


Caused by: java.lang.IncompatibleClassChangeError: Class org.hibernate.internal.SessionImpl does not implement the requested interface jakarta.persistence.EntityManager
        at org.grails.orm.hibernate.HibernateGormStaticApi$_list_closure1.doCall(HibernateGormStaticApi.groovy:79)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Steps I checked,

excluded default hibernate-ehcache included explicitly and excluded hibernate-core

    implementation ("org.grails.plugins:hibernate5"){
      exclude module: "hibernate-ehcache"
    }
    implementation ("org.hibernate:hibernate-ehcache:5.6.15.Final"){
      exclude module: "hibernate-core"
    }

Now the hibernate dependencies

grails-datastore-gorm-hibernate5-9.0.0-M2.jar
hibernate-commons-annotations-5.1.2.Final.jar
hibernate-core-jakarta-5.6.15.Final.jar
hibernate-ehcache-5.6.15.Final.jar
hibernate-validator-8.0.2.Final.jar
hibernate5-9.0.0-M2.jar

Starting application without hibernate-core throws below error

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

SingletonEhcacheRegionFactory not present in hibernate-core-jakarta

Including hibernate-core higher version hibernate-core-6.6.4.Final.jar which has jakarta.persistence.EntityManager implementation throws below error

implementation group: 'org.hibernate.orm', name: 'hibernate-core', version: '6.6.4.Final'

https://github.com/hibernate/hibernate-orm/blob/6.6/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory

It is only available upto hibernate-core-5.6

https://github.com/hibernate/hibernate-orm/blob/5.6/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/SingletonEhcacheRegionFactory.java

@jamesfredley
Copy link
Contributor

org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory lives in org.hibernate:hibernate-ehcache:5.6.15.Final.

@anil-subudhi If you remove the following does it resolve the NoClassDefFoundError?

    exclude module: "hibernate-ehcache"

I am going to work on the hibernate-core exclude on #951

@anil-subudhi
Copy link
Author

@jamesfredley Sorry for the late reply

If I remove exclude ehcache from hibernate5, the SingletonEhcacheRegionFactory issue resolves but it throws

Caused by: java.lang.IncompatibleClassChangeError: Class org.hibernate.internal.SessionImpl does not implement the requested interface jakarta.persistence.EntityManager

as hibernate-ehcache includes hibernate-core:5.6.15 and org.hibernate.internal.SessionImpl not present in 5.6.15 version

https://github.com/hibernate/hibernate-orm/blob/6.6/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

implementation ("org.grails.plugins:hibernate5"){
      //exclude module: "hibernate-ehcache"
}

 +--- org.hibernate:hibernate-ehcache:5.6.15.Final
|    |    +--- org.jboss.logging:jboss-logging:3.4.3.Final -> 3.6.1.Final
|    |    +--- org.hibernate:hibernate-core:5.6.15.Final

Explicitly adding hibernate-ehcache like doesn't resolve SingletonEhcacheRegionFactory

    implementation ("org.grails.plugins:hibernate5"){
      exclude module: "hibernate-ehcache"
    }
   
     implementation ("org.hibernate:hibernate-ehcache:5.6.15.Final"){
      exclude module: "hibernate-core"   // exclude 5.6.15 version
    }

@matrei
Copy link
Contributor

matrei commented Feb 11, 2025

Hi @anil-subudhi

Explicitly adding hibernate-ehcache like doesn't resolve SingletonEhcacheRegionFactory

That is surprising!
What is the error message?

For testing purposes, could you try:

implementation 'org.grails.plugins:hibernate5:9.0.0-M2', {
    exclude group: 'org.hibernate', module: 'hibernate-ehcache'
}
runtimeOnly 'org.hibernate:hibernate-ehcache:5.6.15.Final', {
    // exclude javax variant of hibernate-core 5.6
    exclude group: 'org.hibernate', module: 'hibernate-core'
}
runtimeOnly 'org.jboss.spec.javax.transaction:jboss-transaction-api_1.3_spec:2.0.0.Final', {
    // required for hibernate-ehcache to work with javax variant of hibernate-core excluded
}

@anil-subudhi
Copy link
Author

Thank you @matrei for quick reply,

org.jboss.spec.javax.transaction:jboss-transaction-api_1.3_spec:2.0.0.Final

Resolves the SingletonEhcacheRegionFactory, without jboss-transaction-api_1.3_spec it throws NoClassDefFoundError

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory

@matrei
Copy link
Contributor

matrei commented Feb 11, 2025

OK @anil-subudhi, thanks for the confirmation!
This will be documented as required when using org.hibernate:hibernate-ehcache in Grails 7 with Hibernate 5.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants