Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
In Grails / GORM, what is the difference between
static mapping = {xyz lazy: false}
&
static fetchMode = [xyz: 'eager']
?
Example:
class Book {
static belongsTo = [author: Author]
static mapping = {author lazy: false}
static fetchMode = [author: 'eager']
–
–
–
lazy:false will get the associated domain object by querying again to database using Select Query, but fetchMode 'eager' which is deprecated now(use fetch:'join') will try to join the associated tables(using outer join) and fetch the associated objects in single query.
lazy:false will have one more query to the database to fetch the associated domain object and hence would be having more interactions with the database whereas fetch:'join' will have less interaction to fetch the same data.
FetchMode Join overrides the lazy property. It will simple ignore the lazy:false.
Should you be interested in a detailed explanation about Fetchmodes, take a look http://www.solidsyntax.be/2013/10/17/fetching-collections-hibernate/. The article describes the Hibernate fetchmodes and the output which they produce.
Hope this helps.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.