2017-10-19 2 views
0

Ich versuche Redundanz zu vermeiden, indem ich das zweite Argument an die Methode mit Listengröße übergebe. Stattdessen verwende ich EL, aber ich habe einen Fehler:Warum die SPEL-Unterstützung in Spring Data JPA @Query nicht funktioniert?

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); 

} 

I Feder-data-JPA 1.11.0.RELEASE verwenden. Ich weiß, dass diese Funktion in Version 1.4 entwickelt wurde. Warum funktioniert es nicht in meinem Fall ...

Antwort

1

Die Antwort ist einfach: beliebige Ausdrücke sind nicht implementiert/unterstützt.

Bitte überprüfen Sie sorgfältig auf Spring Data JPA documentaiton bezüglich 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

und die Tabelle der unterstützten Ausdrücke enthält nur

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.

Verwandte Themen