2017-10-19 179 views
0

我试图避免与传递第二个参数法列表大小的冗余。相反,我使用EL,但我有一个错误:为什么规划环境地政司的支持并不在Spring数据JPA @Query工作?

org.hibernate.QueryException: Not all named parameters have been set: [$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); 

} 

我用弹簧数据的JPA 1.11.0.RELEASE。我知道,这个功能是在1.4版本开发。为什么它不会在我的情况下工作...

回答

1

答案很简单:任意表达式没有实现/支持。

请仔细检查有关Using SpEL expressions

As of Spring Data JPA release 1.4 we support the usage of restricted SpEL template expressions in manually defined queries via @Query

而且支持的表达式表春天JPA的数据载文只包含

Variable: entityName

Usage: select x from #{#entityName} x

Description: Inserts the entityName of the domain type associated with the given Repository. The entityName is resolved as follows: If the domain type has set the name property on the @Entity annotation then it will be used. Otherwise the simple class-name of the domain type will be used.

相关问题