grails-core
grails-core copied to clipboard
NPE during startup when running with JDK15
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.
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)
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.
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?
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
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?
Any solutions to this issue? I updated from 3.3 to 5.3.2 and am getting this error.
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'
}
Did anyone find any solution to the problem?
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.
Same issue here on Grails 6.2.0 on adding a datasource dynamically
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: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.createRuntime(AbstractConnectionSourceFactory.java:70) at org.grails.datastore.mapping.core.connections.InMemoryConnectionSources.addConnectionSource(InMemoryConnectionSources.groovy:51) at org.grails.datastore.mapping.core.connections.AbstractConnectionSources.addConnectionSource(AbstractConnectionSources.groovy:96)
Does anyone have a solution or work around to this? I've just hit it again 12 months later. Same situation, I've created a new domain class, added a many to many relationship and it's failing on the same completely different domain class that has sub classes as before.
As before, if I go through the debug logs, GrailsDomainBinder goes through the mapping twice. On the second time, it hits the classes with the subclass and I get the null pointer exception. If I remove the many to many relationship (nothing to do with the subclassed domains), GrailsDomainBinder only goes through once and works fine.
An update for my situation. It seems the NPE is a red herring error, for me at least. I disabled the dependency to spring boot devtools and it revealed an issue with my Flyway DB management. Once I had fixed this, I re-enabled devtools and it worked fine. Hopefully this might help others.
@cdausmus I literally spent 2 full days trying everything under the sun disabling springboot dev tools finally gave me an error I could debug properly.
For context I started seeing this error when we migrated from a single table with 5 discriminator columns (i know awful data modeling but I'm inheriting legacy code) to a tablePerHierarchy model with subdomains and a single formalized discriminator column. One specific sub-class was causing the java.lang.NullPointerException: Cannot invoke "org.grails.orm.hibernate.cfg.Mapping.getBatchSize()" because "m" is null exception. Once I disabled springboot dev tools it revealed the masked error was actually due to an erroneous @Transactional annotation on a helper method on the domain entity. GORM was trying to map the transactionManager to a non-existent transaction_manager column in the database. Removing @Transactional from the domain methods resolved the issue.
@snaco Great job ... could you give an example how was helper method was defined, i.ex. is it something like this?
@Transactional def helpMeOut() { .... }