Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,9 @@ else if ( method.getEnclosingElement().getKind().isInterface()
}

primaryEntity = primaryEntity( lifecycleMethods );
if ( primaryEntity != null && !hasAnnotation(primaryEntity, ENTITY)
|| !checkEntities(lifecycleMethods)) {
final boolean hibernateRepo = isExplicitlyHibernateRepository();
if ( !checkEntity( primaryEntity, hibernateRepo )
|| !checkEntities( lifecycleMethods, hibernateRepo ) ) {
// NOTE EARLY EXIT with initialized = false
return;
}
Expand Down Expand Up @@ -468,6 +469,29 @@ && containsAnnotation( method, HQL, SQL, FIND ) ) {
initialized = true;
}

private boolean checkEntity(@Nullable TypeElement entity, boolean hibernateRepo) {
if ( entity != null && !hasAnnotation( entity, ENTITY ) ) {
if ( hibernateRepo ) {
context.message( element,
"unrecognized primary entity type: " + entity.getQualifiedName(),
Diagnostic.Kind.ERROR );
}
return false;
}
return true;
}

private boolean isExplicitlyHibernateRepository() {
final AnnotationMirror repository = getAnnotationMirror( element, JD_REPOSITORY );
if ( repository != null ) {
final AnnotationValue provider = getAnnotationValue( repository, "provider" );
return provider != null && provider.getValue().toString().equalsIgnoreCase( "hibernate" );
}
else {
return false;
}
}

/**
* Creates a generated id class named {@code Entity_.Id} if the
* entity has multiple {@code @Id} fields, but no {@code @IdClass}
Expand Down Expand Up @@ -612,7 +636,7 @@ private boolean isEquivalentPrimitiveType(TypeMirror type, TypeMirror match) {
&& isSameType( context.getTypeUtils().boxedClass( ((PrimitiveType) type) ).asType(), match );
}

private boolean checkEntities(List<ExecutableElement> lifecycleMethods) {
private boolean checkEntities(List<ExecutableElement> lifecycleMethods, boolean hibernateRepo) {
boolean foundPersistenceEntity = false;
VariableElement nonPersistenceParameter = null;
for (ExecutableElement lifecycleMethod : lifecycleMethods) {
Expand All @@ -637,7 +661,7 @@ else if ( declaredType == parameterType
message(nonPersistenceParameter,
"parameter type '" + nonPersistenceParameter.asType()
+ "' is not a Jakarta Persistence entity class (skipping entire repository)",
Diagnostic.Kind.WARNING);
hibernateRepo ? Diagnostic.Kind.ERROR : Diagnostic.Kind.WARNING);
}
return nonPersistenceParameter == null;
}
Expand Down