2017-10-19 76 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.

相關問題