【发布时间】:2014-11-20 19:49:58
【问题描述】:
如何使用 Hibernate 的分离条件解决此查询?对我来说最难的部分是将and u1.abrechnungsDatum is null 带入子选择。
我想要这样的查询:
select *
from
patient as p
where
p.krankenstand = ?
and
? < ( select count(*) from ueberweisung u1 where p.id = u1.patient_id
and u1.abrechnungsDatum is null)
这个我试过了
DetachedCriteria dc = DetachedCriteria.forClass(Patient.class, "patient");
dc.add(Restrictions.eq("krankenstand", true));
DetachedCriteria nab = dc.createCriteria("ueberweisungs", "nab");
nab.add(Restrictions.isNull("nab.abrechnungsDatum"));
dc.add(Restrictions.sizeGt("ueberweisungs", 0));
这给了我以下 SQL 语句
select
*
from
patient this_
inner join
ueberweisung nab1_
on this_.id=nab1_.patient_id
where
this_.krankenstand=?
and nab1_.abrechnungsDatum is null
and ? < (
select
count(*)
from
ueberweisung
where
this_.id=patient_id
)
如您所见,abrechnungsDatum 字段的 and 子句不在子选择内。我怎样才能做到这一点?
【问题讨论】:
标签: java hibernate detachedcriteria