gorm-hibernate5 icon indicating copy to clipboard operation
gorm-hibernate5 copied to clipboard

NPE during startup when running with JDK15

Open arixmkii opened this issue 4 years ago • 10 comments

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.

arixmkii avatar Oct 15 '20 22:10 arixmkii

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)

tyler-boyd avatar Nov 11 '20 21:11 tyler-boyd

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 avatar Oct 07 '21 15:10 arixmkii

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?

arixmkii avatar Oct 07 '21 17:10 arixmkii

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 avatar Feb 22 '23 15:02 daptordarattler

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?

daptordarattler avatar Feb 22 '23 17:02 daptordarattler

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

randyjones avatar Jun 26 '23 18:06 randyjones

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'
}

krishnact avatar Dec 07 '23 08:12 krishnact

Did anyone find any solution to the problem?

user-yormen avatar Apr 12 '24 09:04 user-yormen

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.

cdausmus avatar Apr 19 '24 07:04 cdausmus