本文介绍了休眠,获取重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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(); //获取重复值

$ / code $ / pre
$ b $ pi.getId( )会返回重复值。即: * 9,9,10,10,11,11等*



但是,直接运行此查询in mysql

  SELECT * FROM JBPM_PROCESSINSTANCE J where J.END_ is NULL 

不会返回重复的值。

任何人都可以发现错误吗?

解决方案

快速的workarround将使用一个Distinct Root Entity Result Transformer。

  ... 
crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
List unique = crit.List();
...

但这只是一个工作周。



我质疑属于您的映射的问题。如果从ProcessInstance到另一个(称为X)存在任何预先加载的1:n关系,并且对于一个ProcessInstance有几个(n)X,则您将在结果列表中获得多个ProcessInstance项目(n) processInstance的。 - 如果这是真正的原因,那么workarround不仅仅是一个工作周,那么它就是解决方案。


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?

解决方案

The fast workarround would be to use a Distinct Root Entity Result Transformer.

...
crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
List unique = crit.List();
...

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.

这篇关于休眠,获取重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 03:51