試圖子查詢的時候,我有兩個實體投標,並BidStatus,投標有屬性的長期與BidStatusUnvalid語法異常在JPQL
Set<BidStatus> Bid.bidStatuses [OneToMany]
Bid BidStatus.parentBid [ManyToOne]
一個一對多的關係BidStatus有:
- 標籤:字符串
- 日期:日期(LOCALDATE的)
什麼我'嘗試做我■選擇所有狀態爲「標籤=狀態」且日期介於日期前和日期後之間的所有出價。
現在我嘗試以下查詢:
select b from Bid b
where b.statuses in (select S from BidStatus S
WHERE
S.label = :status
and S.date >= :before
and S.date <= :after)
但使用此查詢我有以下異常:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
編輯: 我能使其運行使用以下查詢:
select b from Bid b
where EXISTS " +
(select S from BidStatus S
WHERE
S.label = :status
and S.date >= :before
and S.date <= :after
and S.parentBid = b)
但我仍然不明白第一個錯在哪兒。
「IN」用於檢查集合中是否存在元素;你似乎想檢查一個集合中的集合的存在 - 因此這是錯誤的假設。我還假設「b.statuses」是「b.bidStatuses」,以匹配您所說的字段。 –
你是對的我沒有正確使用IN運算符:) – mteffaha