Hibernate fetching strategy - when to use “join” and when to use “select”?

前端 未结 6 2110
栀梦
栀梦 2020-12-22 18:54

Most Hibernate associations support \"fetch\" parameter:

fetch=\"join|select\"

with \"select\" being default value.

How to decide

6条回答
  •  离开以前
    2020-12-22 19:45

    People are always talk about performance hit using fetch=JOIN. But as i reckon, it is important for us to understand the number of parent/child records we are fetching:

    If you want to fetch only single Parent record and expecting it doesn't have many children, then i would suggest you to use fetch=SELECT.

    If you want to fetch all parent records including its children, then it would be better to go for fetch=JOIN

    Just to add a note that, if records are lazily fetching children(lazy=true), then it wouldn't make any sense of using fetch=JOIN since the all the parent and child records gets loaded in a single shot.

提交回复
热议问题