grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' loads hibernate5 non-jakarta

Open jamesfredley opened this issue 7 months ago • 2 comments

When factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' is present in application.yml, the org.hibernate:hibernate-ehcache dependency is loaded with the non-jakarta version of hibernate-core which causes method not found errors given Grails 7 uses the Jakarta version.

hibernate:
    allow_update_outside_transaction: true
    cache:
        queries: false
        use_second_level_cache: true
        use_query_cache: false
        region:
            factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory'

The workaround is to define the org.hibernate:hibernate-ehcache dependency directly with the exclude, but we need to identify what is loading it and attempt to exclude the non-jakarta version of hibernate-core by default.

https://github.com/grails-plugins/grails-audit-logging-plugin/pull/244/files/7892e9cbde72a07438bf3b416b6b6f0457bcbe96#diff-0940648752e294ad17fe3e7b76f2999bee97caa527f5e5036a0d47f743f22805R38

jamesfredley avatar May 08 '25 22:05 jamesfredley

FYI: In Grails 6, we're setting the cache.region.factory_class to jcache in our project. We are also using the dependency:

  api "org.ehcache:ehcache"

Instead of the hibernate version. I think this is probably what we should change the ehcache libraries to use.

jdaugherty avatar May 14 '25 17:05 jdaugherty

Looking at profiles and forge we do not configure factory_class in generated apps, so this is an issue for legacy apps where factory_class: 'org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory' was configured manually.

After org.ehcache:ehcache is tested and works for Grails 7, I think we should update all of the following locations to recommend it instead. In the documentation I think we should steer users to jcache, but we might also keep the bit about hibernate ehcache for the end user that wants to stick with it.

https://github.com/search?q=repo%3Aapache%2Fgrails-core%20factory_class&type=code

forge has a feature for https://github.com/grails-plugins/grails-cache-ehcache/blob/master/build.gradle, but it is already using org.ehcache:ehcache ,It has not been updated for Grails 7.

jamesfredley avatar Jun 06 '25 14:06 jamesfredley