Hibernate 3.2.2 and 3.1.3
I have a simple query to load Cars based on Classification, (many to many relationship)
I have applied Criteria.DISTINCT_ROOT_ENTITY to prevent duplicates that can arise.
Code:
Criteria c = session.createCriteria(Car.class)
.addOrder(Order.asc("id"))
.createCriteria("classifiedAs")
.add(Restrictions.or(
Restrictions.eq("name", "CLASS0"), Restrictions.eq("name", "CLASS1") ));
c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List rs = c.list();
for (Object object : rs)
{
System.out.println("Car:" + object);
}
this gives the following output,
Car:{id:32769, name:Car1}
Car:{id:32770, name:Car2}
So far so good, however when I use scroll instead of list
Code:
ScrollableResults rs = c.scroll();
while( rs.next() )
{
System.out.println("Car:"+ rs.get(0));
}
I get duplicates
Car:{id:32769, name:Car1}
Car:{id:32769, name:Car1}
Car:{id:32770, name:Car2}
Car:{id:32770, name:Car2}
I have looked at the docs/forums/JIRA and there is a lot info but no one seems to be able to clarify if this is a bug or not.
To me it's a bug as criteria.list and criteria.scroll should return the same results. It looks like criteria.scroll doesn't obey the DISTINCT_ROOT_ENTITY contract.
Can someone point me to the appropriate doc/faq to clarify this?
Thanks,
Conor.