From f4d17be10ce1f5379f410407ea40f7d0a764514c Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sat, 3 Feb 2024 00:11:43 +0100 Subject: [PATCH] small fixes to @Find and @HQL methods don't include session parameter type where not necessary --- .../annotation/AbstractFinderMethod.java | 49 +++++++++++-------- .../jpamodelgen/annotation/QueryMethod.java | 3 +- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractFinderMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractFinderMethod.java index 3cb9afd564..658562dc8a 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractFinderMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractFinderMethod.java @@ -88,28 +88,37 @@ public abstract class AbstractFinderMethod extends AbstractQueryMethod { .append("{@link ") .append(annotationMetaEntity.importType(entity)) .append("} by "); - int paramCount = paramNames.size(); - for (int i = 0; i < paramCount; i++) { - String param = paramNames.get(i); - if ( i>0 ) { - if ( i + 1 == paramCount) { - declaration - .append(paramCount>2 ? ", and " : " and "); //Oxford comma - } - else { - declaration - .append(", "); + long paramCount = paramTypes.stream() + .filter(type -> !isOrderParam(type) && !isPageParam(type) + && !isSessionParameter(type)) + .count(); + int count = 0; + for (int i = 0; i < paramTypes.size(); i++) { + String type = paramTypes.get(i); + if ( !isPageParam(type) && !isOrderParam(type) + && !isSessionParameter(type) ) { + if ( count>0 ) { + if ( count + 1 == paramCount) { + declaration + .append(paramCount>2 ? ", and " : " and "); //Oxford comma + } + else { + declaration + .append(", "); + } } + count++; + final String path = paramNames.get(i) + .replace('$', '.'); + declaration + .append("{@link ") + .append(annotationMetaEntity.importType(entity)) + .append('#') + .append(qualifier(path)) + .append(' ') + .append(path) + .append("}"); } - final String path = param.replace('$', '.'); - declaration - .append("{@link ") - .append(annotationMetaEntity.importType(entity)) - .append('#') - .append(qualifier(path)) - .append(' ') - .append(path) - .append("}"); } declaration .append('.') 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 e4c5908e0c..a1a439c5c7 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 @@ -254,7 +254,8 @@ public class QueryMethod extends AbstractQueryMethod { else { return stem + "_" + paramTypes.stream() - .filter(name -> !isPageParam(name) && !isOrderParam(name)) + .filter(type -> !isPageParam(type) && !isOrderParam(type) + && !isSessionParameter(type)) .map(StringHelper::unqualify) .reduce((x,y) -> x + '_' + y) .orElse("");