本文介绍了Hibernate list()是否有效返回重复项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道Hibernate的 Criteria.list() Query.list()方法的有效性多次出现相同的实体?



偶尔我会在使用Criteria API时发现,改变我的类映射定义中的默认获取策略(从select到join )有时会影响对 list()的结果输出中出现同一实体的引用次数,我不确定是否将此视为错误。 javadoc没有定义它,它只是说匹配的查询结果列表。 (感谢球员)。

如果这是预期的和正常的行为,那么我可以自己去清单,这不是问题,但如果它是一个错误,那么我宁愿避免它,而不是去除结果,并试图忽略它。



任何人都有这方面的经验?

解决方案

是的,如果您构建查询以便发生这种情况,那么获取重复是完全可能的。请参阅


Is anyone aware of the validity of Hibernate's Criteria.list() and Query.list() methods returning multiple occurrences of the same entity?

Occasionally I find when using the Criteria API, that changing the default fetch strategy in my class mapping definition (from "select" to "join") can sometimes affect how many references to the same entity can appear in the resulting output of list(), and I'm unsure whether to treat this as a bug or not. The javadoc does not define it, it simply says "The list of matched query results." (thanks guys).

If this is expected and normal behaviour, then I can de-dup the list myself, that's not a problem, but if it's a bug, then I would prefer to avoid it, rather than de-dup the results and try to ignore it.

Anyone got any experience of this?

解决方案

Yes, getting duplicates is perfectly possible if you construct your queries so that this can happen. See for example Hibernate CollectionOfElements EAGER fetch duplicates elements

这篇关于Hibernate list()是否有效返回重复项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:22