gorm - Grails eager dynamic finder -
if load list of domain classes using dynamic finder, e.g.
list<book> books = book.findallbypublicationyear(2013)
my understanding list of books lazily loaded, such if iterate on them
books.each { println "$it.title" }
i execute n + 1 queries. there way make dynamic finder eagerly load list of books (without rewriting query using hql or criteria)?
dynamic finder eager fetch (non-associated) members of domain. example, if publicationyear
being part of book
run 1 query books matching plublicationyear
. query looks like
select this_.id id0_0_, this_.version version0_0_, this_.name name0_0_,this_.publication_year publicat4_0_0_ book this_ this_.publication_year=?
in case have association in book
(author
) can programmatically in domain class whether want fetch
association eagerly
or lazily
using mapping:(default lazy)
static mapping = { author lazy: false //or authors if have multiple authors book }
or
static fetchmode = [author: 'eager']
Comments
Post a Comment