【问题标题】:queryDSL: Fetch record by equating set element using IdqueryDSL:通过使用 Id 使集合元素相等来获取记录
【发布时间】:2014-03-20 12:03:45
【问题描述】:

我想根据student_id获取college_id,其中College包含Set<Student> students. 我正在查询

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

传入的student 实例只包含主键。 抛出的异常是

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.

请提出正确的查询。

【问题讨论】:

    标签: querydsl


    【解决方案1】:

    正确的查询字符串应该是这样的

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

    clg.students.any() 是 Querydsl 语法,不能在 JPQL 查询字符串中使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-26
      • 1970-01-01
      • 2012-12-14
      • 1970-01-01
      • 2013-07-29
      • 2020-04-06
      相关资源
      最近更新 更多