• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returns multiple records one-to-many association

 
Jacky S Zhang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using following code to retrieve from table to entity object



But I'm getting duplicate master records.

Master has 30 records, each record has 6 children caseatt, master to caseatt is ont-to-many, caseatt to attrib is one-to-one. Above code I'm getting 180 records, and each record has a collection(caseatt) of 6 children... Is this normal? I was expecting to get 30 records with each has 6 children...

Anyone can help? Thanks..

Jacky
 
Jacky S Zhang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just figure it out. Add DISTINCT


return getHibernateTemplate().find("select DISTINCT master From Master as master Left join fetch master.caseatts atts inner join fetch atts.attribs");
 
Jacky S Zhang
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works too:


DetachedCriteria criteria = DetachedCriteria.forClass(Master.class).createCriteria("caseatts").setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
return getHibernateTemplate().findByCriteria(criteria);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic