Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude hibernate-ehcache #955

Open
wants to merge 8 commits into
base: 9.0.x
Choose a base branch
from
Open

Conversation

jamesfredley
Copy link
Contributor

@jamesfredley jamesfredley commented Feb 4, 2025

resolves hibernate-core and hibernate-core-jakarta being on the classpath

#951

@matrei
Copy link
Contributor

matrei commented Feb 5, 2025

Couple of thoughts about this:

  1. org.hiberate:hibernate-ehcache is, what I can see, not a dependency of neither grails-datastore-gorm-hibernate5 or grails-plugin and can be removed as such.
  2. org.hibernate:hibernate-ehcache is a testRuntimeOnly dependency of grails-plugin as tests explicitly sets the hibernate:cache:region.factory_class to classes from org.hibernate:hibernate-ehcache in configuration.
  3. org.hibernate:hibernate-ehcache is a runtimeOnly dependency of examples-grails-hibernate as it explicitly sets the hibernate:cache:region.factory_class to org.hibernate.cache.ehcache.EhCacheRegionFactory in application.yml.
  4. Making org.jboss.spec.javax.transaction:jboss-transaction-api_1.3_spec a dependency of grails-plugin should not be needed.

I believe it is the responsibility of the consumer of org.hibernate:hibernate-ehcache to make sure it is on the classpath and that an incompatible version of org.hibernate:hibernate-core is excluded from it, if it causes conflicts.

@jamesfredley If you agree with these thoughts, would you like me to add them to this PR?

@jamesfredley
Copy link
Contributor Author

@matrei

org.hiberate:hibernate-ehcache is, what I can see, not a dependency of neither grails-datastore-gorm-hibernate5 or grails-plugin and can be removed as such.

This is true and it was removed around Sept of 2024, but then broke a number of tests in other Grails projects which depended upon it being provided by the hibernate5 plugin historically. So it is a trade off of a breaking change for Grails apps using ehcache during Grails 7 upgrade vs removing a dependency that is not directly used by the plugin. ehache does not exist for hibernate6, so when gorm-hibernate6 is ready, jcache will be part of the transition.

Making org.jboss.spec.javax.transaction:jboss-transaction-api_1.3_spec a dependency of grails-plugin should not be needed.

If we remove org.hiberate:hibernate-ehcache as a grails-plugin dependency, there are cases like #955 (comment) where the end user will need to include it, like the following:

implementation "org.hibernate:hibernate-ehcache:$hibernateVersion", {
    exclude group:'org.hibernate', module:'hibernate-core'
}
// required for org.hibernate:hibernate-ehcache to work with org.hibernate:hibernate-core-jakarta
implementation "org.jboss.spec.javax.transaction:jboss-transaction-api_1.3_spec:$jbossTransactionApiVersion", {
    exclude group:"jakarta.enterprise", module:"jakarta.enterprise.cdi-api"
}

A quick start to the list of locations that will need to have org.hibernate:hibernate-ehcache added:

@matrei
Copy link
Contributor

matrei commented Feb 5, 2025

So it is a trade off of a breaking change for Grails apps using ehcache during Grails 7 upgrade vs removing a dependency that is not directly used by the plugin

I’d prefer a breaking change in a major version update rather than continuing with the wrong approach. Why should every Grails app using org.grails.plugins:hibernate5 include this dependency, even if it’s not needed? This "kitchen-sink" approach adds unnecessary complexity and makes it harder for users to understand the libraries they depend on. I believe a cleaner, more intentional dependency structure benefits everyone in the long run.

If we remove org.hiberate:hibernate-ehcache as a grails-plugin dependency, there are cases like #955 (comment) where the end user will need to include it, like the following

I looked through the issues related to this PR but couldn’t find a project demonstrating the need for org.jboss.spec.javax.transaction:jboss-transaction-api_1.3_spec.

It seems that BookControllerUnitSpec works when adding testRuntimeOnly 'org.hibernate:hibernate-ehcache' to the grails-plugin project. What am I missing?

@jamesfredley
Copy link
Contributor Author

@matrei Ok, please proceed with the changes.

It seems that BookControllerUnitSpec works when adding testRuntimeOnly 'org.hibernate:hibernate-ehcache' to the grails-plugin project. What am I missing?

That is excellent news, as I did not like adding that javax dependency.

I'll be glad to work on updating the other Grails projects after this breaking change.

Moved `hibernate-ehcache` to a runtime dependency where needed for tests, making it optional and reducing unnecessary module coupling.

As a result, applications using `hibernate-ehcache` will now need to explicitly add it as a dependency.
@matrei matrei changed the title Exclude hibernate-core & add jboss-transaction-api Exclude hibernate-ehcache Feb 5, 2025
@jdaugherty
Copy link
Contributor

Can we update the upgrade guide for Grails 7 to include these instructions since it is a breaking change?

@jamesfredley jamesfredley added this to the 7.0.0-M2 milestone Feb 6, 2025
@matrei
Copy link
Contributor

matrei commented Feb 7, 2025

Can we update the upgrade guide for Grails 7 to include these instructions since it is a breaking change?

grails/grails-doc#951

@@ -26,6 +26,7 @@ dependencies {
runtimeOnly 'org.grails:grails-plugin-services'
runtimeOnly 'org.grails:grails-plugin-url-mappings'
runtimeOnly 'org.grails.plugins:fields'
runtimeOnly "org.hibernate:hibernate-ehcache:$hibernateVersion"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the following to document the right approach and avoid conflicts from the javax version?

, {
    exclude group:'org.hibernate', module:'hibernate-core'
}


testRuntimeOnly "org.hibernate:hibernate-ehcache:$hibernateVersion"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the following to document the right approach and avoid conflicts from the javax version?

, {
    exclude group:'org.hibernate', module:'hibernate-core'
}

testRuntimeOnly "com.h2database:h2"
testRuntimeOnly "org.apache.tomcat:tomcat-jdbc"
testRuntimeOnly "org.hibernate:hibernate-ehcache:$hibernateVersion"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the following to document the right approach and avoid conflicts from the javax version?

, {
    exclude group:'org.hibernate', module:'hibernate-core'
}

@jamesfredley
Copy link
Contributor Author

@matrei The documentation updates on grails/grails-doc#951 look great. What do you think about the 3 small changes I commented on the code?

Even if it does not cause issues in this project, we explicitly exclude
the `javax` variant of `hibernate-core` from `hibernate-ehcache` to
document best practices and prevent potential conflicts in other setups.
@matrei
Copy link
Contributor

matrei commented Feb 7, 2025

@jamesfredley Well, that failed spectacularly😄 . I'll check what's needed to make it run again.

@jamesfredley
Copy link
Contributor Author

@matrei It is the same error that I say initially.

The following does resolve it, although I still think it is suboptimal since it includes 19 javax.transaction.* classes.

// required for org.hibernate:hibernate-ehcache to work with org.hibernate:hibernate-core-jakarta
implementation "org.jboss.spec.javax.transaction:jboss-transaction-api_1.3_spec:$jbossTransactionApiVersion", {
    exclude group:"jakarta.enterprise", module:"jakarta.enterprise.cdi-api"
}

@matrei
Copy link
Contributor

matrei commented Feb 7, 2025

The following does resolve it, although I still think it is suboptimal since it includes 19 javax.transaction.* classes

@jamesfredley Yes, you are right. The question is where we put the responsibility to add this. I would like to say on the application as we have already concluded hibernate-ehcache is an application concern. But it can be added as a runtimeOnly dependency and I think the exclusion of jakarta.enterprise.cdi-api is not needed as it is marked as provided.

@jamesfredley
Copy link
Contributor Author

@matrei I agree it is an application concern and am onboard with reducing the scope when we can. For this project we can add it as needed, for the 3 runtimeOnly/testRuntimeOnly locations in the projects.

Excluding the `javax` variant from `hibernate-ehcache` requires explicitly
including `jboss-transaction-api`.
- Revise the instructions for using GORM in a Spring Boot application.
- Simplify the `application.yml` file in the Spring Boot test project.
@matrei
Copy link
Contributor

matrei commented Feb 8, 2025

I agree it is an application concern and am onboard with reducing the scope when we can. For this project we can add it as needed, for the 3 runtimeOnly/testRuntimeOnly locations in the projects.

@jamesfredley Excellent! Changes made, please review.

@jdaugherty
Copy link
Contributor

I worry about this change. The gorm documentation (under Getting Started) recommends ehcache be included. Caching is a critical component of hibernate and we are definitely making this harder to include because of the extra gradle workarounds that are needed. We need to be sure to update the gorm docs for these workarounds so people understand this is only until we have hibernate 6.

@matrei
Copy link
Contributor

matrei commented Feb 8, 2025

The gorm documentation (under Getting Started) recommends ehcache be included.

Yes, exactly! The documentation does not say that hibernate-ehcache is provided transitively. It says to include it explicitly.

We need to be sure to update the gorm docs for these workarounds so people understand this is only until we have hibernate 6.

Yes, it looks very outdated and needs to be updated.

@jamesfredley
Copy link
Contributor Author

I will work on PRs for the following documentation updates:

grails/grails-doc#953
grails/grails-core#14008
grails/grails-data-mapping#1876

@jamesfredley
Copy link
Contributor Author

I will also try to preemptively address the following, which will break with this change.

https://github.com/search?q=org%3Agrails+org.hibernate.cache.ehcache+language%3AYAML&type=code&l=YAML

@jamesfredley jamesfredley self-assigned this Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Hibernate integration throws NoSuchMethodError for org.hibernate.cfg.AccessType in v9.0.0-M2
3 participants