这是我的解决方案.它只能部分工作:
Criterion subQ1 = Subqueries.propertyIn("id",
DetachedCriteria.forClass(OpB.class)
.add(Restrictions.eq("account", account))
.createAlias("account", "_account")
.add(Restrictions.eq("_account.owner", "John"))
.setProjection(Projections.groupProperty("id")));
Criterion subQ2 = Subqueries.propertyIn("id",
DetachedCriteria.forClass(OpC.class)
.add(Restrictions.eq("account", account))
.createAlias("account", "_account")
.add(Restrictions.eq("_account.owner", "John"))
.setProjection(Projections.groupProperty("id")));
session.createCriteria(Operacao.class)
.add(Restrictions.disjunction()
.add(subQ1)
.add(subQ2))
.list();
只要我不添加命令,它就可以工作:.addOrder(Order.asc(“_ account.owner”)).
订单无法添加到子查询中,因为它不起作用.
它无法添加到Criteria中,因为它不接受别名.
也许有一种方法可以调整它,或者这个解决方案太复杂了,而且更简单?