8

从 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

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

谁能指出我正确的方向,以找出触发的位置以及如何解决它?

4

3 回答 3

10

您还需要指定 hasMany 地图。似乎仅添加List<DomainClassName> listName 您的Domain-Class是不够的

你还需要添加

static hasMany = [
        listName: DomainClassName
]

至少它对我有用。

于 2014-12-03T12:01:35.947 回答
10

找出问题所在

您需要做的第一件事是找出导致问题的字段。很可能它是声明List.

就我而言,很容易找到它们,因为该项目处于非常早期的阶段并且没有太多的域。

但是,我找到了一种可能的解决方案来缩小可能的罪魁祸首。

有趣的部分是:

糟糕的是找出它们在哪里的唯一好方法是在 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])
于 2014-10-31T23:50:19.463 回答
-3

尝试List用真实类的东西替换有问题的接口,例如ArrayList

于 2014-11-02T16:38:41.727 回答