From 2cfe93cd887c12fc5046571be9d744c536e407d6 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sat, 2 Sep 2023 18:58:33 +0200 Subject: [PATCH] fix @Find method with varargs Order parameter --- .../jpamodelgen/annotation/AbstractQueryMethod.java | 9 +++++++++ .../jpamodelgen/annotation/CriteriaFinderMethod.java | 1 + .../hibernate/jpamodelgen/annotation/QueryMethod.java | 11 ----------- .../java/org/hibernate/jpamodelgen/test/dao/Dao.java | 6 ++++++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractQueryMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractQueryMethod.java index ac5542720c..dad4cc0741 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractQueryMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractQueryMethod.java @@ -15,6 +15,7 @@ import org.hibernate.query.Page; import java.util.List; +import static java.util.stream.Collectors.toList; import static org.hibernate.jpamodelgen.util.Constants.SESSION_TYPES; import static org.hibernate.jpamodelgen.util.TypeUtils.isPrimitive; @@ -69,6 +70,14 @@ public abstract class AbstractQueryMethod implements MetaAttribute { abstract boolean isNullable(int index); + List parameterTypes() { + return paramTypes.stream() + .map(paramType -> isOrderParam(paramType) && paramType.endsWith("[]") + ? paramType.substring(0, paramType.length() - 2) + "..." + : paramType) + .collect(toList()); + } + String parameterList() { return paramTypes.stream() .map(this::strip) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/CriteriaFinderMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/CriteriaFinderMethod.java index c9fb8f171f..d8498036c6 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/CriteriaFinderMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/CriteriaFinderMethod.java @@ -46,6 +46,7 @@ public class CriteriaFinderMethod extends AbstractFinderMethod { @Override public String getAttributeDeclarationString() { + final List paramTypes = parameterTypes(); final StringBuilder declaration = new StringBuilder(); comment( declaration ); modifiers( declaration ); diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/QueryMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/QueryMethod.java index fbd18d34f5..e4c5908e0c 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/QueryMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/QueryMethod.java @@ -9,12 +9,9 @@ package org.hibernate.jpamodelgen.annotation; import org.checkerframework.checker.nullness.qual.Nullable; import org.hibernate.internal.util.StringHelper; import org.hibernate.jpamodelgen.util.Constants; -import org.hibernate.query.Order; -import org.hibernate.query.Page; import java.util.List; -import static java.util.stream.Collectors.toList; import static org.hibernate.jpamodelgen.util.StringUtil.getUpperUnderscoreCaseFromLowerCamelCase; /** @@ -205,14 +202,6 @@ public class QueryMethod extends AbstractQueryMethod { return type; } - private List parameterTypes() { - return paramTypes.stream() - .map(paramType -> isOrderParam(paramType) && paramType.endsWith("[]") - ? paramType.substring(0, paramType.length() - 2) + "..." - : paramType) - .collect(toList()); - } - private void comment(StringBuilder declaration) { declaration .append("\n/**"); diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/dao/Dao.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/dao/Dao.java index a3c01352c6..50fd3955b6 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/dao/Dao.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/dao/Dao.java @@ -74,4 +74,10 @@ public interface Dao { @Find List beansForText(String text); + + @HQL("where isbn = ?1") + List sortedBooksForIsbn(String isbn, Order... order); + + @Find + List sortedBooks(String isbn, Order... order); }