0

I have entities :Student, Class, Room.

student M-M class, student M-M rooms, thus two junction tables. Now I want to get all students assigned to class X and room Y. Thus I've made:

@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); 

But it gives me wrong results. Is there an error in my query ?

1
  • 1
    I think you should not use LIKE when searching by id Commented Apr 12, 2018 at 21:01

1 Answer 1

1

The only error in your query is the LIKE statement. Just change the equal sign "=". As below:

@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); 

The LIKE statement allows a greater mass of data. Because it would allow any Room or Class that part of the code is the id entered as a parameter. LIKE statement specification

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.