diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java index 705de9f862..54a0454880 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java @@ -1370,6 +1370,13 @@ private int countNaturalIdFields(TypeElement entity) { private @Nullable FieldType validateFinderParameter(TypeElement entityType, VariableElement param) { final Element member = memberMatchingPath( entityType, parameterName( param ) ); if ( member != null) { + if ( containsAnnotation( member, MANY_TO_MANY, ONE_TO_MANY, ELEMENT_COLLECTION ) ) { + context.message( param, + "matching field is a collection", + Diagnostic.Kind.ERROR ); + return null; + } + final String memberType = memberType( member ).toString(); final String paramType = param.asType().toString(); if ( !isLegalAssignment( paramType, memberType ) ) { @@ -1379,17 +1386,18 @@ private int countNaturalIdFields(TypeElement entity) { Diagnostic.Kind.ERROR ); } - if ( containsAnnotation( member, Constants.ID, Constants.EMBEDDED_ID ) ) { + if ( containsAnnotation( member, ID, EMBEDDED_ID ) ) { return FieldType.ID; } - else if ( containsAnnotation( member, Constants.NATURAL_ID ) ) { + else if ( containsAnnotation( member, NATURAL_ID ) ) { return FieldType.NATURAL_ID; } else { return FieldType.BASIC; } } - final AnnotationMirror idClass = getAnnotationMirror( entityType, Constants.ID_CLASS ); + + final AnnotationMirror idClass = getAnnotationMirror( entityType, ID_CLASS ); if ( idClass != null ) { final Object value = getAnnotationValue( idClass, "value" ); if ( value instanceof TypeMirror ) { @@ -1398,6 +1406,7 @@ else if ( containsAnnotation( member, Constants.NATURAL_ID ) ) { } } } + context.message( param, "no matching field named '" + parameterName( param ).replace('$', '.')