difference between FetchMode and FetchType

后端 未结 2 1698
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-24 05:52

what is the difference in specifying lazy = \"true\" and using fetch = \"select\" or \"join\" ? which one is preferred over the other ?

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 06:42

    FetchMode : It defines how hibernate (using which strategy, e.g. Join, SubQuery etc) will fetch data from database.

    FetchType : It defines whether hibernate will fetch the data or not.

    UPDATES (as per suggestions from comments)

    FetchMode isn't only applicable with FetchType.EAGER. The rules are as follows: a) if you don't specify FetchMode, the default is JOIN and FetchType works normal, b) if you specify FetchMode.JOIN explicitly, FetchType is ignored and a query is always eager, c) if you specify FetchMode.SELECT or FetchMode.SUBSELECT, FetchType.Type works normal

提交回复
热议问题