Grails / GORM: difference between lazy: false & fetchMode impatience

In Grails / GORM, what is the difference between static mapping = {xyz lazy: false} and static fetchMode = [xyz: 'eager'] ?

Example:

 class Book { static belongsTo = [author: Author] static mapping = {author lazy: false} static fetchMode = [author: 'eager'] } 
+7
fetch grails gorm lazy-loading eager-loading
source share
1 answer

Difference between lazy: false and fetchMode 'eager'

  • lazy: false will get the linked domain object, querying the database again with Select Query, but the fetchMode 'eager' that is deprecated now (use fetch: 'join') will try to join the linked tables (using an external join) and select the related objects in one request.
  • lazy: false will have another database query to retrieve the associated domain object and, therefore, will have more interaction with the database, while fetching β€œjoin” will have less interaction to retrieve the same data.
  • FetchMode Join overrides the lazy property. This will simply ignore the lazy: false.

If you are interested in a detailed explanation about Fetchmodes, see http://www.solidsyntax.be/2013/10/17/fetching-collections-hibernate/ . This article describes the Hibernate fibmate models and the output that they produce.

Hope this helps.

+4
source share

All Articles