How to override FetchType.EAGER to be lazy at runtime

后端 未结 2 1724
闹比i
闹比i 2021-01-04 12:08

Using the JPA EntityManager and the JPA Query object, how can I override something that has the annotation @OneToMany(fetch = FetchType.EAGER) to be fetched lazily in a quer

相关标签:
2条回答
  • 2021-01-04 12:33

    Look into Hibernate Fetch profiles, or JPA Entity Graphs. This problem has been solved since you've asked the question in 2012.

    0 讨论(0)
  • 2021-01-04 12:48

    There is no way to do that, even with the native Hibernate API. If an association is defined as EAGER, it will always be eagerly loaded, and there's no way to change that using a query.

    The reverse is not true: you can eagerly-load a lazy association using a query.

    0 讨论(0)
提交回复
热议问题