Hibernate version:
hibernate-3.1rc2
hibernate-annotations-3.1beta6
I seem to get different results with LAZY vs. EAGER fetching on this relationship. The two entities involved are Group and Resource with a bidirectonal OneToMany / ManyToOne
Here's the relevant beans / annotations
Code:
public class ResourceBean {
...
@ManyToOne( fetch=FetchType.EAGER )
private GroupBean group;
}
public class GroupBean {
...
@OneToMany( mappedBy="group", fetch=***FetchType.EAGER***)
private Set<ResourceBean> resources = new HashSet<ResourceBean>();
}
If the highlighted fetchType is EAGER, and I do a 'findAll' on Group, I get duplicate entries from the Resources join. If the fetch type is LAZY, the results are as I'd expect (one object per Group).
I'm using the code patterns in CaveatEmptor demo, so the findall is....
Code:
public List<T> findAll() {
return findByCriteria();
}
protected List<T> findByCriteria(Criterion... criterion) {
Criteria crit = getSession().createCriteria(getPersistentClass());
for (Criterion c : criterion) {
crit.add(c);
}
return crit.list();
}
The Eager SQL is basically...
Code:
select * from groups this_
left outer join resources resources3_ on this_.groupId=resources3_.group_groupId
Am I doing something wrong or is this a bug? Is it my responsibility to somehow unique in the findByCriteria? (eg. I've seen posts about putting results in a Set to remove duplicates). Just doesn't seem right to have to do that here, so I figured I'd post...