tolerate Set + Collection for multivalued @Query parameters

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-03 12:17:38 +02:00
parent cf4af826fe
commit dcacbadd5f
2 changed files with 13 additions and 0 deletions

View File

@ -2665,6 +2665,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
final String argType = stripTypeAnnotations(argumentType);
return param.allowMultiValuedBinding()
? isLegalAssignment(argType, LIST + '<' + queryParamType + '>')
|| isLegalAssignment(argType, SET + '<' + queryParamType + '>')
|| isLegalAssignment(argType, COLLECTION + '<' + queryParamType + '>')
: isLegalAssignment(argType, queryParamType);
}

View File

@ -12,8 +12,10 @@ import org.hibernate.query.SelectionQuery;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;
public interface Dao {
@ -56,6 +58,15 @@ public interface Dao {
@Find
SelectionQuery<Book> createBooksSelectionQuery(String title);
@HQL("where isbn in ?1")
List<Book> booksGivenIsbnList(List<String> isbns);
@HQL("where isbn in :isbns")
List<Book> booksGivenIsbnSet(Set<String> isbns);
@HQL("where isbn in :isbns")
List<Book> booksGivenIsbnCollection(Collection<String> isbns);
@HQL("where title like ?1")
List<Book> findBooksByTitle(String title);