grails-data-mapping icon indicating copy to clipboard operation
grails-data-mapping copied to clipboard

`lazy: false` seems not work in Grails 3.3.5.

Open CHAAAAA opened this issue 6 years ago • 4 comments

Hi, I use Grails3.3.5, lazy: false seems not work. When execute Airport.findByName("Gatwick"), only one SQL statement generated. But if I change it to fetch: 'join', it works well.

| OS: macOS 10.13.5
| Grails Version: 3.3.5
| Groovy Version: 2.4.15
| JVM Version: 1.8.0_111
// Domain Classes
class Airport {
    String name
    static hasMany = [flights: Flight]

    static mapping = {
        flights lazy: false
    }
}
class Flight {
    String number
    Location destination
    static belongsTo = [airport: Airport]
}
class Location {
    String city
    String country
}
// Controller
def airport = Airport.findByName("Gatwick")
println 'start access data...'
println ''

for (flight in airport.flights) {
    println ''
    println 'load Location data...'
    println flight.destination.city
}
// log
Hibernate: select this_.id as id1_0_0_, this_.version as version2_0_0_, this_.name as name3_0_0_ from airport this_ where this_.name=? limit ?

start access data...

Hibernate: select flights0_.airport_id as airport_5_1_0_, flights0_.id as id1_1_0_, flights0_.id as id1_1_1_, flights0_.version as version2_1_1_, flights0_.number as number3_1_1_, flights0_.destination_id as destinat4_1_1_, flights0_.airport_id as airport_5_1_1_ from flight flights0_ where flights0_.airport_id=?

load Location data...
Hibernate: select location0_.id as id1_4_0_, location0_.version as version2_4_0_, location0_.city as city3_4_0_, location0_.country as country4_4_0_ from location location0_ where location0_.id=?

load Location data...
Hibernate: select location0_.id as id1_4_0_, location0_.version as version2_4_0_, location0_.city as city3_4_0_, location0_.country as country4_4_0_ from location location0_ where location0_.id=?

CHAAAAA avatar Jun 22 '18 08:06 CHAAAAA

We are also facing same issue with Grails 3.3.9. We had to change from lazy:'false' to fetch:'join'. Any update on the issue?

vsachinv avatar Dec 09 '19 12:12 vsachinv

I'm also seeing this in Grails 4.0.3

billgonemad avatar Aug 20 '20 12:08 billgonemad

I am also seeing this in Grails 4.0.4

xqliu avatar Oct 20 '20 10:10 xqliu

Same here. Tested with Grails 5 and 6.

We are currently migrating a Grails 2.5.6 application to Grails 5 and this is our main issue. According to the documentation, this should still be supported and working.

Is it still actually supported, is there something special to do to make it work?

jsaulou avatar Aug 21 '23 10:08 jsaulou