Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails动态查找器_Grails_Gorm - Fatal编程技术网

Grails动态查找器

Grails动态查找器,grails,gorm,Grails,Gorm,如果我使用动态查找器加载域类列表,例如 List<Book> books = Book.findAllByPublicationYear(2013) 我将执行N+1查询。有没有办法让dynamic finder急切地加载书籍列表(而不使用HQL或条件重写查询)?dynamic finder总是急切地获取域的(非关联的)成员。例如,如果publicationYear是Book的一部分,您将始终运行一个查询以获取与plublicationYear匹配的所有书籍。我的问题看起来像 sel

如果我使用动态查找器加载域类列表,例如

List<Book> books = Book.findAllByPublicationYear(2013)

我将执行N+1查询。有没有办法让dynamic finder急切地加载书籍列表(而不使用HQL或条件重写查询)?

dynamic finder总是急切地获取域的(非关联的)成员。例如,如果
publicationYear
Book
的一部分,您将始终运行一个查询以获取与
plublicationYear
匹配的所有书籍。我的问题看起来像

select this_.id as id0_0_, this_.version as version0_0_, 
this_.name as name0_0_,this_.publication_year as publicat4_0_0_ 
from book this_ 
where this_.publication_year=?
如果你在
书中有关联,比如(
作者
),你可以通过编程在域类中说,你是想
急切地
获取关联,还是想
懒洋洋地
,通过使用此映射:(默认值为lazy)


static fetchMode=[author:'eager']
动态查找程序总是对域的(非关联的)成员进行eager fetch。例如,如果
publicationYear
Book
的一部分,您将始终运行一个查询以获取与
plublicationYear
匹配的所有书籍。我的问题看起来像

select this_.id as id0_0_, this_.version as version0_0_, 
this_.name as name0_0_,this_.publication_year as publicat4_0_0_ 
from book this_ 
where this_.publication_year=?
如果你在
书中有关联,比如(
作者
),你可以通过编程在域类中说,你是想
急切地
获取关联,还是想
懒洋洋地
,通过使用此映射:(默认值为lazy)


staticfetchmode=[作者:'eager']

是Grails的一个版本吗?我启用了sql输出,它只为我生成了一个查询。我在DataSource中使用Grails 2.1.5。groovy您在DataSource块中添加
logSql=true
,在hibernate块中添加
format\u sql=true
。Grails的哪个版本?我启用了sql输出,它只为我生成了一个查询。我在DataSource中使用Grails 2.1.5。groovy在DataSource块中添加
logSql=true
,在hibernate块中添加
format\u sql=true
static mapping = {
        author lazy: false //or authors if you have multiple authors for a Book
    }