我试图避免将列表大小作为方法的第二个参数传递而产生冗余。相反,我使用EL表达式,但是出现错误:
org.hibernate.QueryException: 未设置所有命名参数: [$synthetic$__1] [SELECT distinct b FROM Book b join b.bookHashtags as ht where ht.hashtagName in :tags group by b.uniqueIdentifier having count(ht.uniqueIdentifier) = :$synthetic$__1]
@Repository
public interface BookRepository extends JpaRepository<Book, Long>, JpaSpecificationExecutor<Book> {
@Query("SELECT distinct b FROM Book b join b.bookHashtags as ht where ht.hashtagName in :tags " +
"group by b.uniqueIdentifier having count(ht.uniqueIdentifier) = :#{#tags.size()}")
List<Book> findAllBooksContainedTags(@Param("tags") Set<String> tags);
}
我使用的是spring-data-jpa 1.11.0.RELEASE版本。我知道这个功能是在1.4版本中开发的。为什么在我的情况下它不起作用...