Skip to content

HHH-19463 when we have @Repository(provider="Hibernate") don't skip repo #10155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025
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