I wrote a criteria request in the Grails service class, where I expect a reliable connection to be made, and to avoid lazy loading of child objects when displaying my results either as a JSON response or in my GSP. The request is executed as expected (setting my hibernate.show_sql = true in my DataSource.groovy I can see the request), but when I scan the association in my GSP, I see that Hibernate is executing subsequent requests, as if it were a lazy loading association. I am not convinced that active loading really works. I do not want to set lazy: false in my domain class for these associations.
This is a query for the criteria:
def market = Market.withCriteria(uniqueResult:true){
idEq(marketId)
fetchMode 'resourceAssignments', FetchMode.JOIN
fetchMode 'resourceAssignments.userRole', FetchMode.JOIN
fetchMode 'resourceAssignments.userRole.role', FetchMode.JOIN
fetchMode 'resourceAssignments.userRole.user', FetchMode.JOIN
resourceAssignments{
userRole{
role{
'in'('name', roleNames)
}
}
}
}
- . , , GSP, , Hibernate , resource:
<g:each in="${market.resourceAssignments}" var="ra">
</g:each>
OpenSessionInViewInterceptor No-Op, WebRequestInterceptor openSessionInViewInterceptor resource.groovy . , org.hibernate.LazyInitializationException, , , , , - Hibernate GORM , , .