search

Home  >  Q&A  >  body text

java - What is the difference between select and subselect in Hibernate's fetch attribute? Are there any usage scenarios?

As mentioned, thank you for your advice

高洛峰高洛峰2784 days ago499

reply all(1)I'll reply

  • 为情所困

    为情所困2017-05-17 10:05:48

    • SUBSELECT: avoids N+1 and does not duplicate data, but loads all entities of related types into memory.

    FetchMode.SUBSELECT should look like this:

    SELECT <employees columns>
    FROM EMPLOYEE employees0_
    WHERE employees0_.DEPARTMENT_ID IN
    (SELECT department0_.DEPARTMENT_ID FROM DEPARTMENT department0_)

    FetchMode.SUBSELECT can significantly reduce the number of queries

    I found a very good article

    reply
    0
  • Cancelreply