Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade issue to Grails 2.4.4

I keep getting an error when starting my Grails application after I upgraded from Grails 2.4.3 to 2.4.4 . The full error can be read here: http://pastebin.com/UXQ34JKD

2014-10-31 16:26:32 ERROR [context.GrailsContextLoaderListener] Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': 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 org.hibernate.MappingException: Association references unmapped class: java.util.List
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': 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 org.hibernate.MappingException: Association references unmapped class: java.util.List
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
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 org.hibernate.MappingException: Association references unmapped class: java.util.List
        ... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: java.util.List
        ... 4 more
Caused by: org.hibernate.MappingException: Association references unmapped class: java.util.List
        ... 4 more

It shows an Association references unmapped class: java.util.List

It doesn't say what domain class or any really helpful information. I've tried removing some domain classes and trying to figure what the cause is, but it's large application and I have been unsuccessful.

Can anyone point me in the right direction for figuring out where this is being triggered and how to fix it?

like image 906
Brandon Wagner Avatar asked Oct 31 '14 20:10

Brandon Wagner


People also ask

How do I upgrade a Grails plugin or application?

The best approach to take when upgrading a plugin or application (and if your application is using several plugins the plugins will need upgrading first) is to create a new Grails 3.0 application of the same name and copy the source files into the correct locations in the new application. Before and after interceptors were removed.

Should I upgrade from Grails 3 to hibernate 4?

If you are upgrading from Grails 3.1 there are a few items to take into consideration. Grails 3.2 comes with Spring 4.3 which no longer supports Hibernate 3 and hence Grails 3.2 no longer supports Hibernate 3 either and you will need to upgrade to Hibernate 4 or above.

How to update the grails and Gorm version?

You will need to upgrade your Grails version defined in gradle.properties. ... grailsVersion=3.3.8 ... ... grailsVersion=4.0.4 ... If you were using GORM, you will need to update the version defined in gradle.properties. ... gormVersion=6.1.10.RELEASE ... ... gormVersion=7.0.4 ... GORM DSL entries should be move to runtime.groovy.

What version of Gradle do I use for Grails?

Grails 3 apps by default used Gradle 3.5. Grails 4 apps use Gradle 5. Due to changes in Gradle 5, transitive dependencies are no longer resolved for plugins. If your project makes use of a plugin that has transitive dependencies, you will need to add those explicitly to your build.gradle file.


1 Answers

Finding out what's wrong

The first thing you need to do is to find out which field(s) cause the issue. Likely it'll be any field in a domain class declared as a List.

In my case it was easy to find them, because the project is on very early stage and there is not too much domains.

However, I found a possible solution to narrow down the possible culprits set.

The interesting part is:

What sucks is the only good way to figure out where they are is to set a breakpoint on line 436 of AbstractGrailsDomainBinder and look at the state of affairs

Fixing the issue

When you find the improper fields, it's time to implement a workaround.

Let's assume that our culprit was List authors in a domain class like:

class Book {
   List<Integer> authors // keeps author ids
} 

We need to get rid of the list, of course, so the solution would be something like:

class Book {

    static transients = ['authors']

    String authorIds

    public void setAuthors(List<Integer> authorList) {
        this.authorIds = authorList ? authorList.join(";") : ''
    }

    public List<Integer> getAuthors() {
        return authorIds?.split(";")?.collect { it.toInteger() } ?: []
    }

} 

Possible side effect

I noticed that the setter needs to be called explicitly to work.

I'm quite sure that in previous Grails version the following code would call the setter:

new Book(authors: [1, 2, 3])

But it looks like in Grails 2.4.4 it needs to be done like:

def book = new Book()
book.setAuthors([1, 2, 3])
like image 162
Marcin Świerczyński Avatar answered Oct 05 '22 02:10

Marcin Świerczyński