@@ -417,8 +417,9 @@ else if ( method.getEnclosingElement().getKind().isInterface()
417
417
}
418
418
419
419
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 ) ) {
422
423
// NOTE EARLY EXIT with initialized = false
423
424
return ;
424
425
}
@@ -468,6 +469,29 @@ && containsAnnotation( method, HQL, SQL, FIND ) ) {
468
469
initialized = true ;
469
470
}
470
471
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
+
471
495
/**
472
496
* Creates a generated id class named {@code Entity_.Id} if the
473
497
* entity has multiple {@code @Id} fields, but no {@code @IdClass}
@@ -612,7 +636,7 @@ private boolean isEquivalentPrimitiveType(TypeMirror type, TypeMirror match) {
612
636
&& isSameType ( context .getTypeUtils ().boxedClass ( ((PrimitiveType ) type ) ).asType (), match );
613
637
}
614
638
615
- private boolean checkEntities (List <ExecutableElement > lifecycleMethods ) {
639
+ private boolean checkEntities (List <ExecutableElement > lifecycleMethods , boolean hibernateRepo ) {
616
640
boolean foundPersistenceEntity = false ;
617
641
VariableElement nonPersistenceParameter = null ;
618
642
for (ExecutableElement lifecycleMethod : lifecycleMethods ) {
@@ -637,7 +661,7 @@ else if ( declaredType == parameterType
637
661
message (nonPersistenceParameter ,
638
662
"parameter type '" + nonPersistenceParameter .asType ()
639
663
+ "' is not a Jakarta Persistence entity class (skipping entire repository)" ,
640
- Diagnostic .Kind .WARNING );
664
+ hibernateRepo ? Diagnostic . Kind . ERROR : Diagnostic .Kind .WARNING );
641
665
}
642
666
return nonPersistenceParameter == null ;
643
667
}
0 commit comments