我从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
Run Code Online (Sandbox Code Playgroud)
它显示了一个 Association references unmapped class: java.util.List
它没有说明什么是域类或任何真正有用的信息.我已经尝试删除一些域类并试图找出原因是什么,但它是大型应用程序,但我没有成功.
任何人都可以指出我正确的方向,找出触发的位置以及如何解决它?
小智 10
您还需要指定hasMany映射.似乎只添加List<DomainClassName> listName
你的Domain-Class就不够了
你还需要添加
static hasMany = [
listName: DomainClassName
]
Run Code Online (Sandbox Code Playgroud)
至少它对我有用.
您需要做的第一件事是找出导致问题的字段.可能它将是声明为a 的域类中的任何字段List.
在我的情况下,很容易找到它们,因为该项目处于非常早期的阶段并且没有太多的域.
但是,我找到了一个可能的解决方案来缩小可能的罪魁祸首.
有趣的是:
什么糟透的是弄清楚它们在哪里的唯一好方法是在AbstractGrailsDomainBinder的第436行设置断点并查看事态
当您找到不正确的字段时,是时候实施变通方法了.
让我们假设我们的罪魁祸首是List authors在域类中:
class Book {
List<Integer> authors // keeps author ids
}
Run Code Online (Sandbox Code Playgroud)
当然,我们需要摆脱列表,所以解决方案将是这样的:
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() } ?: []
}
}
Run Code Online (Sandbox Code Playgroud)
我注意到需要明确调用setter 才能工作.
我很确定在之前的Grails版本中,以下代码将调用setter:
new Book(authors: [1, 2, 3])
Run Code Online (Sandbox Code Playgroud)
但它看起来像在Grails 2.4.4中需要像下面这样完成:
def book = new Book()
book.setAuthors([1, 2, 3])
Run Code Online (Sandbox Code Playgroud)