Hibernate:在 HQL 中覆盖映射的 EAGER? [英] Hibernate: Overriding mapping's EAGER in HQL?

查看:20
本文介绍了Hibernate:在 HQL 中覆盖映射的 EAGER?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用 LEFT JOIN FETCH 覆盖 HQL 中的 LAZY.

It's possible to override LAZY in HQL using LEFT JOIN FETCH.

FROM Obj AS obj LEFT JOIN FETCH obj.otherObj WHERE obj.id = :id

是否也可以覆盖 EAGER?怎么样?

Is it also possible to override EAGER? How?

推荐答案

此代码段中的限定符来自 Hibernate Docs 意味着您可以用 Eager 覆盖惰性,但反之则不行:

The qualifier in this snippet from the Hibernate Docs implies that you can override lazy with eager, but not the other way around:

如果您使用的是属性级惰性获取(使用字节码仪表),可以强制休眠获取懒惰第一个查询中的属性立即使用 fetch all属性.

If you are using property-level lazy fetching (with bytecode instrumentation), it is possible to force Hibernate to fetch the lazy properties in the first query immediately using fetch all properties.

不同寻常的是,如果您使用 Criteria API 从渴望变为懒惰,您似乎可以做到.只需在相关连接上调用 setFetchMode(FetchMode.LAZY).

Unusually, it looks like you can if you use the Criteria API to go from eager to lazy. Just call setFetchMode(FetchMode.LAZY) on the relevant join.

这篇关于Hibernate:在 HQL 中覆盖映射的 EAGER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆