mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-20 10:07:17 +00:00
better cooperation with other Jakarta Data implementations
and with Scott's preprocessor produce WARNINGs instead of ERRORs in some cases Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
baa24d6889
commit
4c1285b609
@ -402,8 +402,8 @@ else if ( method.getEnclosingElement().getKind().isInterface()
|
|||||||
&& !isSessionGetter(method) ) {
|
&& !isSessionGetter(method) ) {
|
||||||
final String companionClassName = element.getQualifiedName().toString() + '$';
|
final String companionClassName = element.getQualifiedName().toString() + '$';
|
||||||
if ( context.getElementUtils().getTypeElement(companionClassName) == null ) {
|
if ( context.getElementUtils().getTypeElement(companionClassName) == null ) {
|
||||||
message( method, "repository method cannot be implemented",
|
message( method, "repository method cannot be implemented (skipping whole repository)",
|
||||||
Diagnostic.Kind.ERROR );
|
Diagnostic.Kind.WARNING );
|
||||||
}
|
}
|
||||||
// NOTE EARLY EXIT with initialized = false
|
// NOTE EARLY EXIT with initialized = false
|
||||||
return;
|
return;
|
||||||
@ -411,6 +411,11 @@ else if ( method.getEnclosingElement().getKind().isInterface()
|
|||||||
}
|
}
|
||||||
|
|
||||||
primaryEntity = primaryEntity( lifecycleMethods );
|
primaryEntity = primaryEntity( lifecycleMethods );
|
||||||
|
if ( primaryEntity != null && !hasAnnotation(primaryEntity, ENTITY)
|
||||||
|
|| !checkEntities(lifecycleMethods)) {
|
||||||
|
// NOTE EARLY EXIT with initialized = false
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !lifecycleMethods.isEmpty() ) {
|
if ( !lifecycleMethods.isEmpty() ) {
|
||||||
validateStatelessSessionType();
|
validateStatelessSessionType();
|
||||||
@ -455,6 +460,36 @@ && containsAnnotation( method, HQL, SQL, FIND ) ) {
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkEntities(List<ExecutableElement> lifecycleMethods) {
|
||||||
|
boolean foundPersistenceEntity = false;
|
||||||
|
VariableElement nonPersistenceParameter = null;
|
||||||
|
for (ExecutableElement lifecycleMethod : lifecycleMethods) {
|
||||||
|
final List<? extends VariableElement> parameters = lifecycleMethod.getParameters();
|
||||||
|
if ( !parameters.isEmpty() ) {
|
||||||
|
final VariableElement parameter = parameters.get(0);
|
||||||
|
final TypeMirror declaredType = parameter.asType();
|
||||||
|
final TypeMirror parameterType = parameterType(parameter);
|
||||||
|
final DeclaredType type = entityType(parameterType);
|
||||||
|
if ( type != null ) {
|
||||||
|
if ( hasAnnotation( type.asElement(), ENTITY ) ) {
|
||||||
|
foundPersistenceEntity = true;
|
||||||
|
}
|
||||||
|
else if ( declaredType == parameterType
|
||||||
|
&& nonPersistenceParameter==null ) {
|
||||||
|
nonPersistenceParameter = parameter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( foundPersistenceEntity && nonPersistenceParameter != null ) {
|
||||||
|
message(nonPersistenceParameter,
|
||||||
|
"parameter type '" + nonPersistenceParameter.asType()
|
||||||
|
+ "' is not a Jakarta Persistence entity class (skipping entire repository)",
|
||||||
|
Diagnostic.Kind.WARNING);
|
||||||
|
}
|
||||||
|
return nonPersistenceParameter == null;
|
||||||
|
}
|
||||||
|
|
||||||
private void validateStatelessSessionType() {
|
private void validateStatelessSessionType() {
|
||||||
if ( !usingStatelessSession(sessionType) ) {
|
if ( !usingStatelessSession(sessionType) ) {
|
||||||
message( element,
|
message( element,
|
||||||
@ -1282,7 +1317,7 @@ else if ( returnType == null ) {
|
|||||||
"incorrect parameter type '" + parameterType + "' is not an entity type",
|
"incorrect parameter type '" + parameterType + "' is not an entity type",
|
||||||
Diagnostic.Kind.ERROR );
|
Diagnostic.Kind.ERROR );
|
||||||
}
|
}
|
||||||
else if ( !containsAnnotation( declaredType.asElement(), ENTITY )
|
else if ( !hasAnnotation( declaredType.asElement(), ENTITY )
|
||||||
// TODO: improve this (carefully consider the case of an erased type variable)
|
// TODO: improve this (carefully consider the case of an erased type variable)
|
||||||
&& declaredParameterType == parameterType ) {
|
&& declaredParameterType == parameterType ) {
|
||||||
message( parameter,
|
message( parameter,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user