我正在尝试创建多次使用相同联接的查询。示例如下所示:
select * from a
join b b1 on b1.id=a.id
join c c1 on c1.id=b1.id
join b b2 on b2.id=a.id
join c c2 on c2.id=b2.id
where b1.attribute = "a" and c1.attribute = "b"
where b2.attribute = "c" and c2.attribute = "d"
我需要利用休眠标准来实现这一点。我在想,这样的方法应该行得通:
Criteria criteria = createCriteria(a.class, "a"); //a would be the class representing table "a"
Criteria criteria1 = criteria.createAlias(b.class, "b1").createAlias(c.class, "c1");
Criteria criteria2 = criteria.createAlias(b.class, "b2").createAlias(c.class, "c2");
但是,我得到了一个QueryException:Duplate关联路径异常。我已经看到了这一点:Hibernate Create Criteria to join the same table twice - tried 2 approach with 2 difference error,但我认为这个解决方案对我不起作用,而且它也意味着它不可能。还有谁的运气更好呢?谢谢!
1条答案
按热度按时间oug3syen1#
我认为这在遗留的Hibernate Criteria API中是不可能的。您应该使用JPA Criteria API,特别是因为遗留的Hibernate Criteria API在Hibernate5中已被弃用,并在Hibernate6中被删除。