2

I am trying to upgrade my application from grails 3.2.11 to 3.3.4 On doing grails run-app, I am getting below errros:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is java.lang.NullPointerException at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271) ... 49 common frames omitted Caused by: java.lang.NullPointerException: null at org.grails.orm.hibernate.cfg.GrailsDomainBinder.getTableName(GrailsDomainBinder.java:1202) at org.grails.orm.hibernate.cfg.GrailsDomainBinder.calculateTableForMany(GrailsDomainBinder.java:1155) at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindCollectionTable(GrailsDomainBinder.java:1105) at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindCollection(GrailsDomainBinder.java:1052) at org.grails.orm.hibernate.cfg.GrailsDomainBinder$CollectionType$1.create(GrailsDomainBinder.java:3463) at org.grails.orm.hibernate.cfg.GrailsDomainBinder.createClassProperties(GrailsDomainBinder.java:1872) at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRootPersistentClassCommonValues(GrailsDomainBinder.java:1751) at org.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRoot(GrailsDomainBinder.java:1391) at org.grails.orm.hibernate.cfg.GrailsDomainBinder.contribute(GrailsDomainBinder.java:165) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:275) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418) at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692) at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:276) 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:204) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrConstructorNewInstance(ReflectiveInterceptor.java:1076) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142) ... 51 common frames omitted

Do anyone has any idea on the same?

Charu Jain
  • 852
  • 1
  • 7
  • 18

3 Answers3

2

I was able to find the reason for this behaviour but still don't know the solution for this with grails 3.3.4

It is due to the "static mapWith" property of domain class e.g AbcType.

class AbcType extends Abc {

static mapWith = "none"

  static mapping = {
    discriminator value: 1
  }

}

I don't want it to be persisted in database. Hence, I have used mapWith property.

If I comment "static mapWith" property of this Domain Class. Then, Everything works seamlessly without any error.

I have checked in 3.3.4 documentation, "static mapWith" property is still supported.

Do anyone has any idea on this behavior. Is there anything I am missing?

Charu Jain
  • 852
  • 1
  • 7
  • 18
  • 1
    You would need to post more to explain your exact situation. As stated above if you have any kind of relationship build on `AbcType` this wont work (ie. if you have hasMany, belongsTo=[AbcType] this will fail as you can not have a relationship with a non-persisted entity). Also as previously stated for 3.3.x if you remove the `mapWith` it seems to behave as in previous versions and if you look at your database is not actually persisting the table. – Rhineb Jun 06 '18 at 13:59
  • I will redesign the domain and its relationships. – Charu Jain Jun 08 '18 at 07:48
2

I looked into this issue and unfortunately this is improper usage of the mapWith static property. The issue is not really the mapWith property but that you have a hasMany on an un-persisted class as that is not supported.

While this may have worked previously (verified your described behavior works up through 3.2.13 with Gorm 6.0.x) it was not a feature, this does not work in Grails 3.3.x with Gorm 6.1.x as relationships such as hasMany will not work with un-persisted classes.

Removing the mapWith appears to allow it to work as it did in previous versions and seems to not cause issues (your milage may vary). You can also remove the relationship and that will also get you past the error. Again though, relationships are designed for persisted objects, so it may be best to consider making some domain updates.

Rhineb
  • 305
  • 3
  • 12
0

For l ran grails clean and everything started working properly

Rutendo
  • 39
  • 2