我有以下类型的查询,我希望将其转换为 jpa 条件查询和以下表结构:
Table A 1-->1 Table B 1<--* Table C (proceedings) *-->1 Table D(prcoeedingsstatus)
-------- -------- ------- -------
aID bID cID dID
... .... timestamp textValue
f_bID .... f_bID
f_dID
1 A 有 1 B,1 B 有很多程序,每个程序都有一个程序状态。
SELECT a.*
FROM ((a LEFT JOIN b ON a.f_b = b.id)
LEFT JOIN proceedings ON b.id = proceedings.f_b)
RIGHT JOIN proceedingsstatus ON proceedings.f_d = proceedingsstatus.id
WHERE d.textValue IN ("some unique text")
AND c.timestamp BETWEEN 'somedate' AND 'anotherdate'
当我现在尝试为谓词做这样的事情时:
Predicate conditions = (root.join("tableB")
.joinList("proceedings")
.join("proceedingsstatus").get("textValue"))
.in(constraintList.getSelectedValues());
Predicate time = cb.between((root.join("tableB")
.joinList("proceedings")
.<Date>get("timestamp")), dt1.toDate(), dt2.toDate());
constraints = cb.and(conditions, time);
现在,如果在 A 的任何程序中“时间戳”与我构建的时间谓词匹配,它会根据条件谓词选择至少出现 1 次正确程序状态的条目 A。因此,如果至少有一个条目 C 属于 A 且 D 中的文本值正确,那么它也会在 C.timestamp 对 D 中带有错误 textValue 的过程正确时选择条目 A。
我怎样才能改变它,使它只选择诉讼状态具有正确价值且收益时间正确的A?