Pregunta

Yo escribo una consulta muy simple, pero estoy consiguiendo valores duplicados por alguna razón.

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
}

El pi.getId() devuelve valores duplicados. es decir: *9,9,10,10,11,11 etc*

Sin embargo, ejecutar esta consulta directamente en MySQL

SELECT * FROM JBPM_PROCESSINSTANCE J where J.END_ IS NULL

no devuelve valores duplicados.

puede manchar a nadie lo que está mal?

¿Fue útil?

Solución

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.

Otros consejos

I encouter the same problem as you..

This is how I solve it.

Criteria cr = session.createCriteria(ProcessInstance.class, "p")
        .add(Restrictions.isNull("end")).setProjection("id")

this will returns all the ID that satisfy all your criteria.

there after you use In restrictions and perform CriteriaSpecification.DISTINCT_ROOT_ENTITY.

You will be able to scroll your result in 2nd criteria.. I hope this help.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top