Difference between FetchType LAZY and EAGER in Java Persistence API?

后端 未结 15 1295
鱼传尺愫
鱼传尺愫 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 08:48

    From the Javadoc:

    The EAGER strategy is a requirement on the persistence provider runtime that data must be eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime that data should be fetched lazily when it is first accessed.

    E.g., eager is more proactive than lazy. Lazy only happens on first use (if the provider takes the hint), whereas with eager things (may) get pre-fetched.

提交回复
热议问题