我需要一些幫助來設置我的查詢。如果我可以避免它,我不想讓多個選擇基本上形成相同的子查詢。在堅果殼中,我有用於跟蹤幾個細節的名爲TimeSlot
的對象。那些TimeSlot
的是支付的項目。當TimeSlot
提交報銷時,他們用於創建PayableTimeSlot
。在支付TimeSlot
之前,我需要確保它尚未支付。JPA避免多個子查詢
因爲它位於下面是我的查詢:
@NamedQuery(
name = "TimeSlot.by.person.academy.id.by.contract.date",
query = "select distinct ts
from TimeSlot ts
join ts.invitedInstructors ii
join ts.academyClass ac
join ac.academy a
where ii.person.id = ?
and a.id = ?
and ts.schedule.startDateTime BETWEEN ? AND ?
and ts.id not in (select e.id from PayableTimeslot pts join pts.event e)
and ? not in (select e.claimant from PayableTimeslot pts join pts.event e)")
正如你可以看到我已經選擇從PayableTimeSot元素的第一not in
。有沒有辦法將子查詢擴展爲: (select e.id, e.claimant from PayableTimeslot pts join pts.event e)
我只是不確定如何檢查多個項目not in
的子查詢。無論如何,如果對問題的解決方法比我所做的更好,請告訴我。
除非你們都認爲多重選擇不會成爲大問題......每個表格每週平均會有30-50個條目被複制(審覈跟蹤)的時間會超過7-9次。