lazy:true, belongsTo defined => eager fetching of whole database on update

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

lazy:true, belongsTo defined => eager fetching of whole database on update

Andre Pietsch
Hi!

Is it intended that if belongsTo is defined on a relation, that this results into eager fetching of records on update of a parent record?

class Continent {
  static hasMany = [countries: Country]
  String continentName
}

class Country {
  static hasMany = [cities: City]
  static belongsTo = Continent
  String countryName
}

class City {
  static belongsTo = Country
  String cityName
}

I have several records in each of these tables.

If I update a Continent-record in this example, all related records down to the City table get eagerly fetched from the database. Explicitly defining lazy:true does not help. It is ignored!

This can be tested with in Config.groovy
log4j {
  debug 'org.hibernate'
}

Is that really intended? Grails references says, that the only meaning of belongsTo is to have GORM manage cascade deletes.

TIA,
Andre
Reply | Threaded
Open this post in threaded view
|

Re: lazy:true, belongsTo defined => eager fetching of whole database on update

Andre Pietsch
Hmm, no, it performs eager fetching in any case... I'll have to investigate further...
scai_andre wrote
Hi!

Is it intended that if belongsTo is defined on a relation, that this results into eager fetching of records on update of a parent record?

class Continent {
  static hasMany = [countries: Country]
  String continentName
}

class Country {
  static hasMany = [cities: City]
  static belongsTo = Continent
  String countryName
}

class City {
  static belongsTo = Country
  String cityName
}

I have several records in each of these tables.

If I update a Continent-record in this example, all related records down to the City table get eagerly fetched from the database. Explicitly defining lazy:true does not help. It is ignored!

This can be tested with in Config.groovy
log4j {
  debug 'org.hibernate'
}

Is that really intended? Grails references says, that the only meaning of belongsTo is to have GORM manage cascade deletes.

TIA,
Andre
Reply | Threaded
Open this post in threaded view
|

Re: lazy:true, belongsTo defined => eager fetching of whole database on update

Andre Pietsch
In reply to this post by Andre Pietsch
Yes, it is as I stated in my first post: belongsTo leads to eager fetching on update.

Is this intended?
scai_andre wrote
Hi!

Is it intended that if belongsTo is defined on a relation, that this results into eager fetching of records on update of a parent record?

class Continent {
  static hasMany = [countries: Country]
  String continentName
}

class Country {
  static hasMany = [cities: City]
  static belongsTo = Continent
  String countryName
}

class City {
  static belongsTo = Country
  String cityName
}

I have several records in each of these tables.

If I update a Continent-record in this example, all related records down to the City table get eagerly fetched from the database. Explicitly defining lazy:true does not help. It is ignored!

This can be tested with in Config.groovy
log4j {
  debug 'org.hibernate'
}

Is that really intended? Grails references says, that the only meaning of belongsTo is to have GORM manage cascade deletes.

TIA,
Andre
Reply | Threaded
Open this post in threaded view
|

Re: lazy:true, belongsTo defined => eager fetching of whole database on update

_dms_
All related records are loaded during validation process. To prevent this behavior you can use modelObject.save(deepValidate:false), but you must do manual validation on all associasions in that case, including embedded :(

I don't know is there a way to validate only loaded or changed associaded objects

scai_andre wrote
Hi!

Is it intended that if belongsTo is defined on a relation, that this results into eager fetching of records on update of a parent record?

class Continent {
  static hasMany = [countries: Country]
  String continentName
}

class Country {
  static hasMany = [cities: City]
  static belongsTo = Continent
  String countryName
}

class City {
  static belongsTo = Country
  String cityName
}

I have several records in each of these tables.

If I update a Continent-record in this example, all related records down to the City table get eagerly fetched from the database. Explicitly defining lazy:true does not help. It is ignored!

This can be tested with in Config.groovy
log4j {
  debug 'org.hibernate'
}

Is that really intended? Grails references says, that the only meaning of belongsTo is to have GORM manage cascade deletes.

TIA,
Andre