我有兩張名為 Student 和 Games 的表。Student Id 是 Games 表中的外鍵,每個學生可以選擇多個游戲(OneToMany 關系)。
在這里,我需要一個 JPQL 查詢來獲取學生串列和游戲串列。條件是:當我們嘗試搜索正在打板球的學生時,回傳的串列應包含所有打板球的學生及其選擇的游戲(包括板球在內的所有游戲)的串列。
示例: 學生 1:足球、板球 學生 2:曲棍球、板球 學生 3:排球、足球 學生 4:板球
預期輸出: 學生 1:足球、板球 學生 2:曲棍球、板球 學生 4:板球
uj5u.com熱心網友回復:
我發現自己在 where 子句的條件下添加了解決方案
select s from studentsEntity s left join fetch gamesEntity g
where s.studentId in (select s1.studentId from studentsEntity s1 left join gamesEntity g1 where s.studentId=s1.studentId and g1.name='Cricket')
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/493983.html
上一篇:我升級到Hibernate6.0,現在出現未知物體錯誤
下一篇:檢查串列中的任何值是否滿足條件
