Hi,
I have been confused with this problem for two days:(
Hibernate version:3
When lazy=false in xml,excute following code:
Code:
result = s.createCriteria(JtsUser.class)
.add(Restrictions.idEq(2))
.list();
result.size() is 1, this is correct.But when lazy=true in xml,excute following in java:
Code:
result = s.createCriteria(JtsUser.class)
.setFetchMode("jtsHistories", FetchMode.JOIN)
.add(Restrictions.idEq(2))
.list();
result.size() is 4, 4 same objects! This is unreasonable because id is PK.
"jtsHistories" is a set of "JtsUser". The JtsUser that id=2 contains 4 records of jtsHistory(
if 5, then 5 same objects).