2017-10-19 34 views
0

J'essaie d'éviter la redondance en passant le second argument à la méthode avec la taille de la liste. Au lieu de cela, j'utiliser EL, mais j'ai une erreur:Pourquoi le support SpEL ne fonctionne pas dans Spring Data 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); 

} 

J'utilise 1.11.0.RELEASE ressort des données JPA. Je sais que cette fonctionnalité a été développée dans la version 1.4. Pourquoi ça ne marche pas dans mon cas ...

Répondre

1

La réponse est simple: les expressions arbitraires ne sont pas implémentées/supportées.

S'il vous plaît vérifier attentivement le printemps de données JPA documentaiton concernant 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

Et la table des expressions prises en charge ne contient que

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.