Gradient GORM Query Eager Fetching Criterion

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 , , .

+5
1

, Grails . HQL:

def market = Market.executeQuery(
    'select m from Market m ' +
    'inner join fetch m.resourceAssignments as ra ' +
    'inner join fetch ra.userRole as ur ' +
    'inner join fetch ur.role as role ' +
    'inner join fetch ur.user as user ' +
    'where m.id=:marketId and role.name in (:roleNames)',
    [marketId: marketId, roleNames: roleNames], [max: 1])[0]
+5
source

All Articles