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 2f895ccf23..30c967b1a2 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 @@ -1409,18 +1409,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { } else { multivalued.add( false ); - final Types types = context.getTypeUtils(); - final TypeMirror parameterType = parameterType( parameter ); - boolean pageRequest = typeNameEquals( parameterType, JD_PAGE_REQUEST ); - if ( isOrderParam( typeName(parameterType) ) || pageRequest ) { - final TypeMirror typeArgument = getTypeArgument( parameterType ); - if ( typeArgument == null ) { - missingTypeArgError( entity.getSimpleName().toString(), parameter, pageRequest ); - } - else if ( !types.isSameType( typeArgument, entity.asType() ) ) { - wrongTypeArgError( entity.getSimpleName().toString(), parameter, pageRequest ); - } - } + checkFinderParameter(entity, parameter); } } putMember( methodKey, @@ -1445,6 +1434,21 @@ public class AnnotationMetaEntity extends AnnotationMeta { ); } + private void checkFinderParameter(TypeElement entity, VariableElement parameter) { + final Types types = context.getTypeUtils(); + final TypeMirror parameterType = parameterType(parameter); + boolean pageRequest = typeNameEquals( parameterType, JD_PAGE_REQUEST ); + if ( isOrderParam( typeName(parameterType) ) || pageRequest ) { + final TypeMirror typeArgument = getTypeArgument( parameterType ); + if ( typeArgument == null ) { + missingTypeArgError( entity.getSimpleName().toString(), parameter, pageRequest ); + } + else if ( !types.isSameType( typeArgument, entity.asType() ) ) { + wrongTypeArgError( entity.getSimpleName().toString(), parameter, pageRequest ); + } + } + } + private void createCriteriaDelete(ExecutableElement method, TypeMirror returnType) { final TypeElement entity = primaryEntity; if ( entity == null) { @@ -2689,23 +2693,27 @@ public class AnnotationMetaEntity extends AnnotationMeta { } } if ( returnType != null ) { - final Types types = context.getTypeUtils(); for ( VariableElement parameter : method.getParameters() ) { - final TypeMirror parameterType = parameterType( parameter ); - final TypeMirror typeArgument = getTypeArgument( parameterType ); - final boolean pageRequest = typeNameEquals(parameterType, JD_PAGE_REQUEST); - if ( isOrderParam( typeName(parameterType) ) || pageRequest ) { - if ( typeArgument == null ) { - missingTypeArgError( returnType.toString(), parameter, pageRequest ); - } - else if ( !types.isSameType(typeArgument, returnType) ) { - wrongTypeArgError( returnType.toString(), parameter, pageRequest ); - } + final TypeElement entity = implicitEntityType(returnType); + if ( entity != null ) { + checkFinderParameter(entity, parameter); } + // else? what? } } } + private @Nullable TypeElement implicitEntityType(@Nullable TypeMirror resultType) { + if ( resultType != null && resultType.getKind() == TypeKind.DECLARED) { + final DeclaredType declaredType = (DeclaredType) resultType; + final Element typeElement = declaredType.asElement(); + if ( hasAnnotation(typeElement, ENTITY) ) { + return (TypeElement) typeElement; + } + } + return primaryEntity; + } + private boolean typeNameEquals(TypeMirror parameterType, String typeName) { if ( parameterType.getKind() == TypeKind.DECLARED ) { final DeclaredType declaredType = (DeclaredType) parameterType;