Difference between FetchType LAZY and EAGER in Java Persistence API?

后端 未结 15 1392
鱼传尺愫
鱼传尺愫 2020-11-22 08:08

I am a newbie to Java Persistence API and Hibernate.

What is the difference between FetchType.LAZY and FetchType.EAGER in Java Persistence API?

15条回答
  •  广开言路
    2020-11-22 09:01

    LAZY: It fetches the child entities lazily i.e at the time of fetching parent entity it just fetches proxy(created by cglib or any other utility) of the child entities and when you access any property of child entity then it is actually fetched by hibernate.

    EAGER: it fetches the child entities along with parent.

    For better understanding go to Jboss documentation or you can use hibernate.show_sql=true for your app and check the queries issued by the hibernate.

提交回复
热议问题