hibernate ver : 3.2.0.cr2 (part of JBoss 4.0.4GA)
Is it normal for a criteria to return duplicate objects?
Like :
Code:
Criteria crit = getSession().createCriteria(Group.class);
crit.add(some criterions);
crit.addOrder(Order.asc("comp_id.key"));
List result = crit.list();
if (result.get(1) == result.get(2)){
System.out.println("woot ?");
}
I tried to add crit.setResultTransformer(DISTINCT_ROOT_ENTITY), which appears to work, but the underlying SQL still returns more rows.
Is it worth optimising the SQL (by tweaking the Criteria, not touching the SQL directly, of course).
Details :
I have a Group class which has a Set of Member classes.
What I want is to get a list of Groups, that match certain conditions (err... Criterions) AND have a non-zero number of Members, that also match some conditions.
What I do now is this :
Code:
Criteria crit = getSession().createCriteria(Group.class);
crit.add(eq("type",3));
crit.createAlias("members", "member").add(gt("member.termination",
new Date()));
crit.addOrder(Order.asc("comp_id.key"));
List result = crit.list();
if (result.get(1) == result.get(2)){
System.out.println("woot ?");
}
I also tried createCriteria("members") instead of createAlias("members", "member") but the result is the same : duplicates.
What happens is, that if a certain Group matches the "type" and has for example 5 members out of which 3 match the "termination", then this group will be 3 times in the criteria result list.
What is the cleanest way to get rid of the duplicates ?
Finally I just need a list of Groups, not info about how many active members they have.
Here is the relevant part of the mapping:
Code:
<set name="members" lazy="true" inverse="true" cascade="none">
<key>
<column name="GROUP_KEY" />
<column name="GROUP_KEY_PART2" />
</key>
<one-to-many
class="com.foo.bar.Member" />
</set>