Grails Eager获取空关联返回null

时间:2012-10-15 08:38:16

标签: grails one-to-many eager empty-list

我有以下域类

Class Author{
String name 

List books = LazyList.decorate(new ArrayList(), FactoryUtils.instantiateFactory(Book.class)


static hasMany = [books:Book]

}

Class Book {
String title
static belongsTo = [author:Author]

}

现在我正在尝试获取作者

Author authorInstance = Author.find("from Author a inner join fetch a.books where a.id =:authorid",[authorid:Long.parseLong(params.id)]

现在,当这位作者没有任何书籍时,即书籍协会是空的 返回的authorInstance为null

我不确定,但我认为这是因为lazyList而发生的(我使用lazyList的原因是为了让数据绑定更容易)。

1 个答案:

答案 0 :(得分:0)

想出问题在于内连接,当关联为空时,内连接显然不会返回任何内容,所以我将其更改为左外连接,并且它开始工作