Farzad,
Thanks again for your reply.
I tried the exact mapping you have, and it seems fine. However, if I insert some sample values into the table ENT1 and ENT2, and if I try to find ENT1 by ID column, the returned records are not correct. For example, if I have sample records as below:
Code:
insert into TEMP.ENT1 values
(101, 201, 'ent1-001'),
(102, 202, 'ent1-002');
insert into TEMP.ENT2 values
(202, 'ENTKEY-001', 'ent2_001'),
(202, 'ENTKEY-002', 'ent2_002'),
(202, 'ENTKEY-003', 'ent2_003');
When I looks up ENT1 by ID 102, I got 3 records (identical) back, and each has 3 ENT2 in the set. Can you please try this out and see whether you get the same problem?
Here are the codes that I retrieve the records for ENT1:
Code:
public List getEntity1List(Integer id, boolean loadSet) {
DetachedCriteria criteria = DetachedCriteria.forClass(Entity1.class);
if (id != null)
criteria.add(Expression.eq("id", id));
if (loadSet)
criteria.setFetchMode("entity2", FetchMode.JOIN);
List list = null;
HibernateTemplate template = hibernateDaoHelper.getHibernateTemplate();
if (template == null)
debug("template is null");
else list = template.findByCriteria(criteria);
return list;
}
Thanks for your help.