将问题升级到Grails 2.4.4

时间:2014-10-31 20:31:56

标签: grails grails-2.4

从Grails 2.4.3升级到2.4.4后,我在启动Grails应用程序时遇到错误。完整错误可在此处阅读: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

显示Association references unmapped class: java.util.List

它没有说出什么是域类或任何真正有用的信息。我尝试删除一些域类并试图弄清楚原因是什么,但它的大型应用程序并没有成功。

有人能指出我正确的方向来确定触发的位置以及如何解决这个问题吗?

3 个答案:

答案 0 :(得分:10)

您还需要指定hasMany地图。似乎只添加List<DomainClassName> listName就不够了 在域类

您还需要添加

static hasMany = [
        listName: DomainClassName
]

至少它对我有用。

答案 1 :(得分:9)

找出错误

您需要做的第一件事是找出导致问题的字段。可能它会被声明为List的域类中的任何字段

在我的情况下很容易找到它们,因为项目处于非常早期的阶段并且没有太多的域名。

然而,我发现possible solution缩小了可能的罪魁祸首。

有趣的部分是:

  

糟糕的是找出它们所在的唯一好方法是在AbstractGrailsDomainBinder的第436行设置断点并查看事态

解决问题

当您找到不正确的字段时,是时候实施变通方法了。

我们假设我们的罪魁祸首是List authors在域类中,如:

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

当然,我们需要摆脱列表,因此解决方案将是:

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() } ?: []
    }

} 

可能的副作用

我注意到需要将显式称为setter才能工作。

我很确定在以前的Grails版本中,以下代码会调用setter:

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

但是在Grails 2.4.4中它看起来像是:

def book = new Book()
book.setAuthors([1, 2, 3])

答案 2 :(得分:-3)

尝试将有问题的List接口替换为真正的类,例如ArrayList