allow overloaded query methods

This commit is contained in:
Gavin King 2023-06-26 20:16:56 +02:00
parent 5141e2b40e
commit eeebf20b9c
2 changed files with 16 additions and 3 deletions

View File

@ -393,7 +393,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
paramTypes,
isNative
);
putMember( attribute.getPropertyName(), attribute );
putMember( attribute.getPropertyName() + paramTypes, attribute );
checkParameters( method, paramNames, mirror, hql );
if ( !isNative ) {

View File

@ -7,11 +7,13 @@
package org.hibernate.jpamodelgen.annotation;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.jpamodelgen.model.MetaAttribute;
import org.hibernate.jpamodelgen.model.Metamodel;
import java.util.List;
import static java.util.stream.Collectors.toList;
import static org.hibernate.internal.util.StringHelper.join;
import static org.hibernate.jpamodelgen.util.StringUtil.getUpperUnderscoreCaseFromLowerCamelCase;
@ -104,7 +106,7 @@ public class QueryMethod implements MetaAttribute {
.append("entityManager.")
.append(isNative ? "createNativeQuery" :"createQuery")
.append("(")
.append(getUpperUnderscoreCaseFromLowerCamelCase(methodName));
.append(getConstantName());
if (returnTypeName != null) {
declaration
.append(", ")
@ -144,13 +146,24 @@ public class QueryMethod implements MetaAttribute {
@Override
public String getAttributeNameDeclarationString() {
return new StringBuilder().append("public static final String ")
.append(getUpperUnderscoreCaseFromLowerCamelCase(methodName))
.append(getConstantName())
.append(" = \"")
.append(queryString)
.append("\";")
.toString();
}
private String getConstantName() {
String stem = getUpperUnderscoreCaseFromLowerCamelCase(methodName);
if ( paramTypes.isEmpty() ) {
return stem;
}
else {
return stem + "_" + StringHelper.join("_",
paramTypes.stream().map(StringHelper::unqualify).collect(toList()));
}
}
@Override
public String getMetaType() {
throw new UnsupportedOperationException();