我有实体:Student
,Class
,Room
。
student M-M class
,student M-M rooms
,因此有两个联结表。现在,我希望将所有students
分配到课程X
和房间Y
。因此我做了:
@Query("SELECT s from Student s INNER JOIN s.classes c INNER JOIN s.rooms r WHERE c.id LIKE ?1 AND r.id LIKE ?2")
Page<Student> findAllInClassAndRoom(final Long classId, final Long roomId, final Pageable pageable);
但它给了我错误的结果。我的查询中是否有错误?
答案 0 :(得分:1)
查询中唯一的错误是LIKE语句。只需更改等号&#34; =&#34;。如下:
@Query("SELECT s from Student s INNER JOIN s.classes c INNER JOIN s.rooms r WHERE c.id = ?1 AND r.id = ?2")
Page<Student> findAllInClassAndRoom(final Long classId, final Long roomId, final Pageable pageable);
LIKE语句允许更大量的数据。因为它允许任何Room或Class代码的一部分是作为参数输入的id。 LIKE statement specification