apache / apache/grails-core

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

Open
#14,563 4 comments 0 reactions 0 assignees View on GitHub
relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

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
```

```groovy
// 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
}
```

```groovy
// 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=?
```

Contributor guide

Open the contributing guide

Research direction

Start with the Airport, Flight, and Location domain mappings and the controller query shown in the report. Reproduce the generated SQL for lazy: false and fetch: 'join', then trace how airport.flights and flight.destination are loaded. Done means the reported eager-loading behavior is understood and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.