grails / gorm-hibernate5

GORM for Hibernate 5
Apache License 2.0
64 stars 69 forks source link

NPE during startup when running with JDK15 #233

Open arixmkii opened 3 years ago

arixmkii commented 3 years ago

Grails 4.1.0.M2 Gorm 7.1.0.M3 Groovy 3.0.6 Java Adoptopenjdk 15

Caused by: java.lang.NullPointerException: Cannot invoke "org.grails.orm.hibernate.cfg.Mapping.getBatchSize()" because "m" is null
    at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindSubClass(GrailsDomainBinder.java:1508)
    at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindSubClasses(GrailsDomainBinder.java:1467)
    at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRoot(GrailsDomainBinder.java:1410)
    at org.grails.orm.hibernate.cfg.GrailsDomainBinder.contribute(GrailsDomainBinder.java:161)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:283)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473)
    at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
    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.<init>(HibernateDatastore.java:212)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:204)
    ... 182 common frames omitted

No matter what is set as target output level. Will fail with application built targeting JDK11, JDK14 or JDK15.

No problems, when running with JDK up to 14 inclusive.

I guess that JDK15 is not yet supported, but this issue can be used for tracking progress.

tyler-boyd commented 3 years ago

I'm having the same issue on JDK8. Only when using a custom UserType (although it's throwing an exception mapping OTHER things than what I put the UserType on)

arixmkii commented 2 years ago

Still present with Grails 5.0.0-RC4 Gorm 7.1.0-RC4 Groovy 3.0.9 Java Temurin 17

With custom user types from hibernate-types-55

grails.gorm.default.mapping = {
  'user-type'(type: com.vladmihalcea.hibernate.type.basic.ZoneIdType, class: java.time.ZoneId)
  'user-type'(type: com.vladmihalcea.hibernate.type.basic.YearMonthDateType, class: java.time.YearMonth)
}

sql-server jdbc driver. Don't know if this thing matters.

arixmkii commented 2 years ago

Related to developmentOnly("org.springframework.boot:spring-boot-devtools")

At least in one case classes resolved in org.grails.orm.hibernate.cfg.GrailsDomainBinder#bindSubClass are loaded from Application classloader, but all caches are filled with Restart classloader.

Don't know if this is still hibernate5 specific or grails in general if this is springboot devtools related?

daptordarattler commented 1 year ago

anyone find a solution to this? I'm having the same issue. After debugging for days on end, I realized it's related to the mapping cache as illustrated above. So I have no idea how to proceed or even have a work around? It actually only showed up after setting up multi-tenancy with discriminator strategy

grailsVersion=5.2.5
grailsGradlePluginVersion=5.2.4
gormVersion=7.3.0
groovyVersion=3.0.11
org.gradle.daemon=true
org.gradle.parallel=true
#org.gradle.jvmargs=-Dfile.encoding=UTF-8 -Xmx1024M
org.gradle.configureondemand=true

Using JDK 17.0.5

daptordarattler commented 1 year ago

Just upgraded to grails 5.3.2 still problem persists. I've double checked all my mappings and nothing seems out of place. Initially I was importing mappings from a trait class. So when the issue started, I decided to implement them directly in all the domain class mappings with all that duplicated code for the mapping. But didn't solve the problem.

Any help?

randyjones commented 1 year ago

Any solutions to this issue? I updated from 3.3 to 5.3.2 and am getting this error.

krishnact commented 10 months ago

I faced this problem when I tried to use a composite id in one of my classes as shown below.

static mapping = {
    id            composite: ['community', 'person']
}

Finally I changed it to use String as Id type (I did not want to use Long) and this error disappeared.

static mapping = {
    id           generator: 'uuid'
}
user-yormen commented 5 months ago

Did anyone find any solution to the problem?

cdausmus commented 5 months ago

I've just started getting this error too on Java 11.

grailsVersion=5.3.0
grailsGradlePluginVersion=5.2.4
groovyVersion=3.0.11
gormVersion=7.3.2
springBootVersion=2.7.9

Was working fine until I added a many to many relationship between two already existing domains. But the kicker is, when I debugged it, it was falling over on the Mapping Cache (as previously noted) on a completely unrelated relationship.

What seems to be happening, when starting the embedded Tomcat in IntelliJ, when I add the many to many relationship, it spawns the Gorm binding process twice and it's the second time that fails. Remove the relationship and it only runs once and starts fine.

Tearing my hair out with this one.