How to override FetchType.EAGER to be lazy at runtime

后端 未结 2 1736
闹比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: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.

提交回复
热议问题