alanbino opened a new issue, #14469:
URL: https://github.com/apache/grails-core/issues/14469

   Consider two domain entities:
   
   ```
   @Entity
   class AParent {
       // ...
       static hasOne = [child:AChild]
       // ...
   }
   ```
   
   ```
   @Entity
   class AChild {
       // ...
       static belongsTo = [parent:AParent]
       // ...
   }
   ```
   
   If I have a list of 10 ids for Entity 'AParent' and make the following call:
   `AParent.findAllByIdInList( aIds )`
   
   This single call (without _ever_ attempting to programmatically access 
'child') immediately triggers 10 additional hibernate sql selects to get each 
individual child (where each AParent hasOne AChild).
   And so one 'findAllByIdInList' call triggers 11 db calls, with no explicit 
requests of the child entity and explicit lazy configuration:
   
   Additionally, there is no way to disable this eager fetching. The following 
static mappings fail to have the desired impact:
   - child fetch: 'select'
   - child fetch: 'lazy'
   - child lazy: 'true'
   
   Example output from the 1 call `AParent.findAllByIdInList( aIds ) // with 10 
ids`
   
   ```Hibernate: select this_.id as id1_1_0_, this_.version as version2_1_0_, 
this_.parent_description as parent_d3_1_0_ from a_parent this_ where this_.id 
in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   Hibernate: select achild0_.id as id1_0_0_, achild0_.version as 
version2_0_0_, achild0_.description as descript3_0_0_, achild0_.parent_id as 
parent_i4_0_0_ from a_child achild0_ where achild0_.parent_id=?
   ```
   
   The main issue is that this relationship *cannot* be configured as lazy (at 
least not any way that I am aware of, and traditional static mappings do not 
work).
   
   Less importantly, it could be argued that the default for the hasOne 
_should_ be lazy (like the hasMany), but this is not the case.
   
   This can be easily reproduced with the following Micronaut 1.1.1 + GORM 
7.0.0 Repository:
   https://github.com/alanbino/gorm-hasone


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to