相关文章推荐
鼻子大的柑橘  ·  arrays - What is a ...·  2 年前    · 
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']
                I think this might answer your question:     [stackoverflow.com/questions/654704/…        [1]: stackoverflow.com/questions/654704/…
– David Chavez
                May 6, 2015 at 13:53
                Thanks for the link, but the answer seems to describe the difference between lazy: true & lazy: false.  The answer doesn't mention fetchMode = [...]
– XDR
                May 7, 2015 at 4:35
                It would be nice it someone could answer this question as I didn't find any explanation on the grails documentation neither on the internet.
– Merlin
                Oct 19, 2015 at 9:17
  • 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.