In Grails 2, we all know that a where clause creates a DetachedCriteria. Also, one can set the fetchMode property of a relationship when creating a normal Criteria query. But, if I’m creating a where-clause query, how do I set the fetchMode property of the underlying Criteria?
Does not work:
MyDomainClass.where {
foo == 'bar'
fetchMode "reference", FetchMode.EAGER
}
works, but uses old Criteria style, not where clause:
MyDomainClass.withCriteria {
eq "foo", "bar"
fetchMode "reference", FetchMode.EAGER
}
Please don’t tell me to set the fetch mode to eager in the domain class mapping. I know about that, and need to control the eager fetching at the query level. Thanks!
This isn’t supported yet, so please create a feature request at http://jira.grails.org/browse/GRAILS
There is a somewhat hackish workaround though by accessing the Hibernate
Criteriainstance that does the actual querying: