0

Context: I am trying to upgrade a Grails project from 1.0.3 to 1.3.7 and am running into a bunch of problems. I just was getting a lot of DuplicateMappingExceptions because the project had Hibernate XML files as well as domain files. I moved the domain files out to src/groovy, but now find myself with a new NullPointerException, and I don't know how to go about resolving it:

2011-05-30 10:27:29,037 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
    at org.grails.tomcat.InlineExplodedTomcatServer.doStart(InlineExplodedTomcatServer.groovy:112)
    at org.grails.tomcat.InlineExplodedTomcatServer$doStart.callCurrent(Unknown Source)
    at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:97)
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
    at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
    at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
    at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
    at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
    at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
    at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
    at RunApp$_run_closure1.doCall(RunApp:33)
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:427)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:415)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.executeTargets(Gant.groovy:590)
    at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
    ... 25 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NullPointerException
    ... 25 more
Caused by: java.lang.NullPointerException
    ... 25 more

It looks like the NullPointerException is in:

Caused by: java.lang.NullPointerException
    at org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty.equals(DefaultGrailsDomainClassProperty.java:506)
    at org.codehaus.groovy.grails.commons.GrailsDomainConfigurationUtil.configureDomainClassRelationships(GrailsDomainConfigurationUtil.java:167)
    at org.codehaus.groovy.grails.commons.DomainClassArtefactHandler.initialize(DomainClassArtefactHandler.java:67)
    at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.initializeArtefacts(DefaultGrailsApplication.java:738)
    at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.initializeArtefacts(DefaultGrailsApplication.java:721)
    at org.codehaus.groovy.grails.commons.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:682)
    at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil.configureDomainClass(GrailsHibernateUtil.java:163)
    at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsHibernateUtil.configureHibernateDomainClasses(GrailsHibernateUtil.java:117)
    at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration.buildSessionFactory(GrailsAnnotationConfiguration.java:124)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
    at org.codehaus.groovy.grails.orm.hibernate.ConfigurableLocalSessionFactoryBean.newSessionFactory(ConfigurableLocalSessionFactoryBean.java:126)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    ... 461 more

This makes it seem like the error is in the Domain Classes (either the classes themselves or the Hibernate XML) that I just moved to src/groovy. I have both domain classes and hibernate xml in the project.

Here are a couple of links that I have found that show a similar stack trace. It definitely seems like something funky in the relationship between the Hibernate XML and the Domain Classes:

6
  • What plugins do you use?
    – Chris
    May 31, 2011 at 8:57
  • Try running grails clean, and see if that fixes anything.
    – Pat
    May 31, 2011 at 14:50
  • @Chris - Just Hibernate, Quartz, Acegi, and Tomcat. I am pretty new to Grails, so it may be something dumb.
    – skaz
    May 31, 2011 at 15:05
  • Try disabling Quartz and Acegi (just comment the lines out in application.properties), and then run again to see if gets further.
    – Chris
    Jun 1, 2011 at 14:54
  • @Chris - I disabled the plugins - no dice. Looks to be a Domain Class issue, but I have no idea how to diagnose.
    – skaz
    Jun 2, 2011 at 14:27

2 Answers 2

1
+50

Looks like you shouldn't use Hibernate mapping on non-domain classes. The exception says that there's a relationship configured that Grails can't find a target property for (see here, line 167). Namely, there's a null in some class' persistentProperties.

I have a very little idea why that bug occurs, but would start with moving all mapped classes to domain, then remove all XML mappings, then start running the app on HQL and adding XML configs back one-by-one. This would narrow the search pretty quickly.

You can also give a shot to debugging Grails itself - the source is available.

2
  • Thanks for your insightful comment. What do you mean by "Hibernate mapping on non-domain classes"? I was under the impression that the Hibernate mapping CREATED domain classes - In other words, that I didn't need to have a domain-name.groovy class for a domain-name.hbm.xml file - that just the mapping file would be genereated into a .class file when compiled. Are you saying that for each .hbm.xml file I should also have a .groovy domain class? Thanks for clearing up my confusion.
    – skaz
    Jun 3, 2011 at 19:18
  • I've been believing that one has to have both class and its cfg.xml. If you don't, then I recommend that you try it :) Can't try it myself now, sorry. Jun 4, 2011 at 15:54
0

Tough to diagnose this, since the stack trace doesn't really have any useful info. I would try increasing the logging to see if that gives any clues, and then start to disable plugins one by one to see if it gets you further.

3
  • I disabled the plugins but it was no help. I also added this logging: log4j = { all 'grails.app', 'org.grails.tomcat' } but it didn't show anything.
    – skaz
    Jun 2, 2011 at 13:53
  • Is there any other logging I should be doing? I don't really know how to proceed...Thanks.
    – skaz
    Jun 2, 2011 at 17:27
  • In the last of your "Similar Stack Trace" links, Graeme Rocher says, "This is because you have an association from your Hibernate mapped class to your GORM domain. Relationships between GORM and hibernate mapped entities don't really work and would take a significant re-write of the ORM binding to support both, which certainly won't make it into 1.2." Is this the case with your project (your hibernate domain classes try to map to GORM domain classes)? If so I would try to migrate these to the GORM domain if possible.
    – Chris
    Jun 3, 2011 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.