Skip to content

Commit 91ea6be

Browse files
committed
HHH-19463 when we have @repository(provider="Hibernate") don't skip repo
in this case it can't be intended for another provider
1 parent 341ab5c commit 91ea6be

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,9 @@ else if ( method.getEnclosingElement().getKind().isInterface()
417417
}
418418

419419
primaryEntity = primaryEntity( lifecycleMethods );
420-
if ( primaryEntity != null && !hasAnnotation(primaryEntity, ENTITY)
421-
|| !checkEntities(lifecycleMethods)) {
420+
final boolean hibernateRepo = isExplicitlyHibernateRepository();
421+
if ( !checkPrimaryEntity( hibernateRepo )
422+
|| !checkEntities( lifecycleMethods, hibernateRepo ) ) {
422423
// NOTE EARLY EXIT with initialized = false
423424
return;
424425
}
@@ -468,6 +469,29 @@ && containsAnnotation( method, HQL, SQL, FIND ) ) {
468469
initialized = true;
469470
}
470471

472+
private boolean checkPrimaryEntity(boolean hibernateRepo) {
473+
if ( primaryEntity != null && !hasAnnotation(primaryEntity, ENTITY) ) {
474+
if ( hibernateRepo ) {
475+
context.message( element,
476+
"unrecognized primary entity type: " + primaryEntity.getQualifiedName(),
477+
Diagnostic.Kind.ERROR );
478+
}
479+
return false;
480+
}
481+
return true;
482+
}
483+
484+
private boolean isExplicitlyHibernateRepository() {
485+
final AnnotationMirror repository = getAnnotationMirror( element, JD_REPOSITORY );
486+
if ( repository != null ) {
487+
final AnnotationValue provider = getAnnotationValue( repository, "provider" );
488+
return provider != null && provider.getValue().toString().equalsIgnoreCase( "hibernate" );
489+
}
490+
else {
491+
return false;
492+
}
493+
}
494+
471495
/**
472496
* Creates a generated id class named {@code Entity_.Id} if the
473497
* entity has multiple {@code @Id} fields, but no {@code @IdClass}
@@ -612,7 +636,7 @@ private boolean isEquivalentPrimitiveType(TypeMirror type, TypeMirror match) {
612636
&& isSameType( context.getTypeUtils().boxedClass( ((PrimitiveType) type) ).asType(), match );
613637
}
614638

615-
private boolean checkEntities(List<ExecutableElement> lifecycleMethods) {
639+
private boolean checkEntities(List<ExecutableElement> lifecycleMethods, boolean hibernateRepo) {
616640
boolean foundPersistenceEntity = false;
617641
VariableElement nonPersistenceParameter = null;
618642
for (ExecutableElement lifecycleMethod : lifecycleMethods) {
@@ -637,7 +661,7 @@ else if ( declaredType == parameterType
637661
message(nonPersistenceParameter,
638662
"parameter type '" + nonPersistenceParameter.asType()
639663
+ "' is not a Jakarta Persistence entity class (skipping entire repository)",
640-
Diagnostic.Kind.WARNING);
664+
hibernateRepo ? Diagnostic.Kind.ERROR : Diagnostic.Kind.WARNING);
641665
}
642666
return nonPersistenceParameter == null;
643667
}

0 commit comments

Comments
 (0)