hibernate 多次 createCriteria 的问题

求教一个hibernate问题,我要用DetachedCriteria写个查询功能如下sql ,
关系如下:
t_site - rel : 1-N
rel - tag : N-1

select s.* from t_site s
LEFT JOIN rel r ON r.site_id=s.id LEFT JOIN tag c ON r.tag_id=c.id
LEFT JOIN rel r2 ON r2.site_id=s.id LEFT JOIN tag c2 ON r2.tag_id=c2.id
where c.id = 'xx' and c2.id = 'yy'
我写的DetachedCriteria 部分代码如下,
DetachedCriteria dc = DetachedCriteria.forClass( TSite.class );
dc.createCriteria( "rel", "r").createCriteria("r.tag", "c");
dc.createCriteria( "rel", "r2").createCriteria("r2.tag", "c2");
dc.add( Restrictions.eq("c.id", "xx"));
dc.add( Restrictions.eq("c2.id", "yy"));

但是报错org.springframework.orm.hibernate3.HibernateQueryException: duplicate association path: rel; nested exception is org.hibernate.QueryException: duplicate association path: rel

我要怎么写才不重复association path?
需要用到DetachedCriteria

查看全部
xuganggogo
xuganggogo
2012/11/18 00:45
  • hibernate
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

0个回复