-
Notifications
You must be signed in to change notification settings - Fork 72
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
Hibernate integration throws NoSuchMethodError for org.hibernate.cfg.AccessType in v9.0.0-M2 #951
Comments
Grails 7 requires migrating everything javax.* to jakarta.* to work with Spring 6.2 and Spring Boot 3.4. You will need to make the same changes in your application. https://github.com/grails/grails-core/blob/7.0.x/UPGRADE7.md lists this and many other breaking changes that were necessary to move to the latest and only OSS supported version of Spring and Spring Boot. |
@anil-subudhi is the problematic app described in the original post one that was created with 7.0.0-M1 or one that was upgraded? |
@jeffscottbrown , I am facing on upgrade to Grails 7.0.0-M1, the build contains below hibernate depedencies grails-datastore-gorm-hibernate5-9.0.0-M2.jar When tried to get list of method of org.hibernate.cfg.AccessType, I don't see any such overloaded methods with jakarta.persistence.AccessType , to resolve this I modified grails-datastore-gorm-hibernate5-9.0.0-M2 and converted to string
org.hibernate.cfg.AccessType methods: |
That is good info. That wasn't clear to me reading through the steps to reproduce, and that is helpful information. Thank you for the clarification! |
hibernate-ehcache is pulling in the non jakarta hibernate-core-5.6.15.Final.jar artifact. Is that causing the issue with duplicate classes on the classpath? I assume only one of the hibernate core libraries should be included? |
Dependence tree:
|
In a newly created 7.0.0-M1 app:
|
I believe we will need to exclude |
Reference to another issue #952 |
Hi @anil-subudhi Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception |
You still have the original hibernate on your classpath. Try adding configurations { to your build.gradle |
Expected Behavior
Library: grails-datastore-gorm-hibernate5-9.0.0.pom
The type casting should be resolved from javax.persistence.AccessType to jakarta.persistence.AccessType while calling
'org.hibernate.cfg.AccessType org.hibernate.cfg.AccessType.getAccessStrategy(jakarta.persistence.AccessType)'
Actual Behaviour
Hibernate integration throws NoSuchMethodError
Caused by: java.lang.NoSuchMethodError: 'org.hibernate.cfg.AccessType org.hibernate.cfg.AccessType.getAccessStrategy(jakarta.persistence.AccessType)'
https://github.com/grails/gorm-hibernate5/blob/v9.0.0-M2/grails-datastore-gorm-hibernate/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java#L2656
AccessType methods are below which doesn't contain overloaded method for org.hibernate.cfg.AccessType.getAccessStrategy(jakarta.persistence.AccessType)
This leads to failure with NoSuchMethodError
AccessType methods:
[public static org.hibernate.cfg.AccessType[] org.hibernate.cfg.AccessType.values(), public static org.hibernate.cfg.AccessType org.hibernate.cfg.AccessType.valueOf(java.lang.String), public java.lang.String org.hibernate.cfg.AccessType.getType(), public static org.hibernate.cfg.AccessType org.hibernate.cfg.AccessType.getAccessStrategy(java.lang.String), public static org.hibernate.cfg.AccessType org.hibernate.cfg.AccessType.getAccessStrategy(javax.persistence.AccessType), public final java.lang.String java.lang.Enum.name(), public final boolean java.lang.Enum.equals(java.lang.Object), public java.lang.String java.lang.Enum.toString(), public final int java.lang.Enum.hashCode(), public int java.lang.Enum.compareTo(java.lang.Object), public final int java.lang.Enum.compareTo(java.lang.Enum), public static java.lang.Enum java.lang.Enum.valueOf(java.lang.Class,java.lang.String), public final java.util.Optional java.lang.Enum.describeConstable(), public final java.lang.Class java.lang.Enum.getDeclaringClass(), public final int java.lang.Enum.ordinal(), public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException, public final void java.lang.Object.wait() throws java.lang.InterruptedException, public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException, public final native java.lang.Class java.lang.Object.getClass(), public final native void java.lang.Object.notify(), public final native void java.lang.Object.notifyAll()]
Caused by: java.lang.NoSuchMethodError: 'org.hibernate.cfg.AccessType org.hibernate.cfg.AccessType.getAccessStrategy(jakarta.persistence.AccessType)'
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindProperty(GrailsDomainBinder.java:2656)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.createProperty(GrailsDomainBinder.java:2313)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindComponentProperty(GrailsDomainBinder.java:2281)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindCompositeId(GrailsDomainBinder.java:1854)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindIdentity(GrailsDomainBinder.java:1814)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRootPersistentClassCommonValues(GrailsDomainBinder.java:1776)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRoot(GrailsDomainBinder.java:1401)
at org.grails.orm.hibernate.cfg.GrailsDomainBinder.contribute(GrailsDomainBinder.java:161)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:292)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:86)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:479)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:85)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:709)
at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:287)
at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:39)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:23)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52)
at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24)
at org.grails.orm.hibernate.HibernateDatastore.(HibernateDatastore.java:212)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:209)
Steps To Reproduce
Environment Information
| Grails Version: 7.0.0-M1
| JVM Version: 17.0.9
Gradle 8.12
OS: Mac OS X 15.1.1 x86_64
Example Application
No response
Version
7.0.0-M1
The text was updated successfully, but these errors were encountered: