2017-10-19 4 views
0

リストサイズのメソッドに第2引数を渡すことで冗長性を避けようとしています。代わりに、私はELを使用しますが、私はエラーを持っている:私は春・データのJPA 1.11.0.RELEASEを使用SpringデータでSpELサポートが動作しない理由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); 

} 

。私はこの機能が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のdocumentaitonに慎重にチェックして、サポートされる式のテーブルは

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.

が含まれています
関連する問題