Spring Data JPQL没有为参数指定值

时间:2018-02-22 07:57:13

标签: spring-data spring-data-jpa jpql

我有两个类Post和Tag。这些是多对多关系,Post有一个属性Set<标签>标签。我想返回包含我提供的所有标签作为参数的帖子。

  

示例:帖子A有标签T1,T2和T3,帖子B有标签T1。我提供了一个标签T1和T3的集合。因此,只应返回帖子A.

在扩展CrudRepository 的 repo界面中,我有以下自定义查询构建:

@Query(
    value="SELECT p, count(p) AS noEntries 
        FROM Post p WHERE p.tags IN :tags 
        GROUP BY p.id HAVING noEntries = :noTags",
    countQuery = "SELECT count(spe) AS noEntries 
        FROM Post spe WHERE spe.tags IN :tags 
        GROUP BY spe.id HAVING noEntries = :noTags")
Page<Post> findAllByTagsInCustom(Pageable pageable, @Param("tags") Set<Tag> tags, 
    @Param("noTags") int noTags);

我用

调用查询
posts = repo.findAllByTagsInCustom(pReq, tags, tags.size());

其中参数是类型PageRequest(pReq),Set(tags)和int(tags.size())。

运行请求时我得到了

Servlet.service() for servlet [dispatcherServlet] in context with path [/v1] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause

java.sql.SQLException: No value specified for parameter 2

如何指定方法参数以使查询有效?

0 个答案:

没有答案