Hibernate,获取重复值
我正在编写一个非常简单的查询,但由于某种原因我得到了重复的值。
Criteria cr = session.createCriteria(ProcessInstance.class, "p")
.add(Restrictions.isNull("end"));
@Cleanup ScrollableResults sr = cr.scroll(ScrollMode.FORWARD_ONLY);
while (sr.next()) {
pi = (ProcessInstance) sr.get(0);
String id = pi.getId(); //Getting duplicate values
}
pi.getId()
返回重复值。 ie: *9,9,10,10,11,11 etc*
但是,直接在 mysql 中运行此查询
SELECT * FROM JBPM_PROCESSINSTANCE J where J.END_ IS NULL
不会返回重复值。
谁能发现哪里出了问题吗?
I am writing a very simple query, but I am getting duplicate values for some reason.
Criteria cr = session.createCriteria(ProcessInstance.class, "p")
.add(Restrictions.isNull("end"));
@Cleanup ScrollableResults sr = cr.scroll(ScrollMode.FORWARD_ONLY);
while (sr.next()) {
pi = (ProcessInstance) sr.get(0);
String id = pi.getId(); //Getting duplicate values
}
The pi.getId()
returns duplicate values. ie: *9,9,10,10,11,11 etc*
However, running this query directly in mysql
SELECT * FROM JBPM_PROCESSINSTANCE J where J.END_ IS NULL
Does not return duplicate values.
Can anyone spot what is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速的解决方法是使用不同的根实体结果转换器。
但这只是一个解决方法。
我想问题出在你的映射上。如果从 ProcessInstance 到其他对象存在任何急切加载的 1:n 关系(称为 X),并且一个 ProcessInstance 有多个 (n) X,则您将在单个 ProcessInstance 的结果列表中获得多个 ProcessInstance 项 (n)流程实例。 -- 如果这确实是原因,那么解决方法不仅仅是解决方法,那么它将是解决方案。
The fast workarround would be to use a Distinct Root Entity Result Transformer.
But this is only a workarround.
I ques the problem belongs to your mapping. If there is any eager loaded 1:n relationship from ProcessInstance to something else (call it X), and there are several (n) X for one ProcessInstance, the you will get several ProcessInstance items (n) in the result list for a single ProcessInstance. -- If this is realy the cause, than the workarround is not just a workarround, then it would be the solution.
我遇到了和你一样的问题..
这就是我解决它的方法。
这将返回满足您所有条件的所有 ID。
在使用
In
限制并执行CriteriaSpecification.DISTINCT_ROOT_ENTITY
后。您将能够在第二个标准中滚动结果。我希望这有帮助。
I encouter the same problem as you..
This is how I solve it.
this will returns all the ID that satisfy all your criteria.
there after you use
In
restrictions and performCriteriaSpecification.DISTINCT_ROOT_ENTITY
.You will be able to scroll your result in 2nd criteria.. I hope this help.