Hibernate:在Criteria API中启用惰性抓取 [英] Hibernate: Enabling lazy fetching in Criteria API

查看:144
本文介绍了Hibernate:在Criteria API中启用惰性抓取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个针对域模型的查询,其中(无论出于何种原因),一对多关联映射为lazy =false。在我特别的问题中,我宁愿懒懒地取出那个集合,因为我不关心它的内容。我怎样才能让我的特殊查询重新获得懒惰?这是可能的吗?



到目前为止,我看着 Criteria.setFetchMode ,但 FetchMode.LAZY 仅仅是 FetchMode.SELECT ...的不推荐别名。



更改映射可能是理想的,但我宁愿不会影响现有查询。



编辑:我们使用Hibernate 3.3.2

解决方案

我自己并不是专家,但浏览Hibernate书籍并与同事协商并没有给我任何暗示这是可能的,相反。

你们似乎是一种不寻常的情况,Hibernate没有涉及。典型的用例是相反的:在默认情况下使用延迟获取,并选择性地为查询提供合理的提前获取。


I am writing a query against a domain model where (for whatever reason) a one-to-many association is mapped with lazy="false". In my particular query, I'd rather fetch that collection lazily, because I don't care about its contents. How can I reenable laziness for my particular query? Is this possible at all?

So far, I looked at Criteria.setFetchMode, but FetchMode.LAZY is merely a deprecated alias for FetchMode.SELECT ...

Changing the mapping would probably be ideal, but I'd rather not risk affecting the existing queries.

Edit: We use Hibernate 3.3.2

解决方案

I am not an expert myself, but browsing through the Hibernate book and consulting with a colleague didn't give me any hint that this would be possible, rather the contrary.

Yours seems to be an unusual situation, not covered by Hibernate. The typical use case is the opposite: to use lazy fetching by default, and selectively enable eager fetching for queries where it is justified.

这篇关于Hibernate:在Criteria API中启用惰性抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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