从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
它没有说出什么是域类或任何真正有用的信息。我尝试删除一些域类并试图弄清楚原因是什么,但它的大型应用程序并没有成功。
有人能指出我正确的方向来确定触发的位置以及如何解决这个问题吗?
答案 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() } ?: []
}
}
我注意到需要将
我很确定在以前的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