我从有效的HQL查询中获得了我需要的SQL查询
Select Temp.*,
(select
case
when count(tab7.id)>0 then 1
else 0
end
from
table7 tab7
where
tab7.id = Temp.col_3_0_
) As Col_6_0_
from (Select
tab5.col1 As Col_0_0_,
tab5.col2 As Col_1_0_,
sum(tab5.col3) as col_2_0_,
tab5.col4 as col_3_0_,
from
table5 tab5,
table1 tab1
table2 tab2
where
tab2.somecol=tab5.somecol
and tab1.id=tab5.id
GROUP BY tab5.col1 ,
tab5.col2 ,
tab5.col4 ) Temp
但是当我尝试以这种方式执行HQL查询时,我正面临语法问题。
问题:
有没有办法在HQL中使用from
cluase中的子查询?
如果没有,我如何在休眠中实现这一目标?
请帮忙。
答案 0 :(得分:0)
您可以使用分离的条件来触发子查询或在hibernate
中的条件中查询下面是您的示例代码
Criteria cr = getSession().createCriteria(Payment.class, "P");
cr.add(Subqueries.propertyNotIn("P.paymentId",DetachedCriteria.forClass(Refund.class, "refund")
.add(Restrictions.or(Restrictions.eq("refund.isCancelled", false),
Restrictions.isNull("refund.isCancelled")))
.setProjection(Property.forName("refund.payment.paymentId"))))
欢呼声