如何使用Hibernate Criteria Query实现以下SQL查询:
select * from Table1 where (A,B) in (select A,B from Table2)
答案 0 :(得分:2)
假设我们有表1的标准和表2的分离标准。下面的代码工作完美无缺:
Criteria criteria = new Criteria(Table1.class);
DetachedCriteria dc = DetachedCriteria.forClass(Table2.class);
ProjectionList projList = Projections.projectionList();
projList.add(Projections.property("column1"));
projList.add(Projections.property("column2"));
dc.setProjection(Projections.distinct(projList));
criteria.add(Subqueries.propertiesIn(new String[]{"column1","column2"}, dc));