Question

I want to get the college_id based on the student_id, where College contains Set<Student> students. I am querying like

@Query("SELECT clg.id FROM College clg WHERE clg.students.any() = (:student)")
public List<Object> getCollegeIdByStudent(@Param("student") Student student);

Passed in student instance contains only the primary key. Exception thrown is

org.springframework.orm.jpa.JpaSystemException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet.

Please suggest correct query.

Was it helpful?

Solution

The correct query string should be something like

SELECT clg.id FROM College clg WHERE :student MEMBER OF clg.students

clg.students.any() is Querydsl syntax and can't be used in a JPQL query string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top