Skip to content

HHH-20720 Copy @InterceptorBinding annotations for all repository types, not just @Repository#13109

Open
FroMage wants to merge 1 commit into
hibernate:mainfrom
FroMage:HHH-20720-main
Open

HHH-20720 Copy @InterceptorBinding annotations for all repository types, not just @Repository#13109
FroMage wants to merge 1 commit into
hibernate:mainfrom
FroMage:HHH-20720-main

Conversation

@FroMage

@FroMage FroMage commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Previously, inheritedAnnotations() only copied annotations with @InterceptorBinding (such as @transactional) to the generated implementation class when the interface was annotated with Jakarta Data's @repository. Quarkus Data repositories without @repository were excluded, so @transactional on their methods was silently lost.

Widen the check from isJakartaDataRepository()/jakartaDataRepository to isRepository()/repository so that all processor-generated repository implementations inherit interceptor binding annotations.

Upstream issue: quarkusio/quarkus#53622

Test is on Quarkus project, as usual.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.



Please make sure that the following tasks are completed:
Tasks specific to HHH-20720 (Bug):

  • Add test reproducing the bug
  • Add entries as relevant to migration-guide.adoc OR check there are no breaking changes

https://hibernate.atlassian.net/browse/HHH-20720

…es, not just @repository

Previously, inheritedAnnotations() only copied annotations with
@InterceptorBinding (such as @transactional) to the generated
implementation class when the interface was annotated with Jakarta
Data's @repository. Quarkus Data repositories without @repository
were excluded, so @transactional on their methods was silently lost.

Widen the check from isJakartaDataRepository()/jakartaDataRepository
to isRepository()/repository so that all processor-generated
repository implementations inherit interceptor binding annotations.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@FroMage

FroMage commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

This is going to need a backport to 7.4. Do you want me to make the backport PR? There are conflicts, I've noticed.

@Override
public List<AnnotationMirror> inheritedAnnotations() {
if ( annotationMetaEntity.isJakartaDataRepository() ) {
if ( annotationMetaEntity.isRepository() ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that also affect Hibernate ORM's "native" repositories type? I seem to remember that was a thing -- you could use the annotation processor to generate (sort of) repositories even without Jakarta Data, using Hibernate-specific annotations.

I'm thinking of this in particular:

jakartaDataRepository = hasAnnotation( element, JD_REPOSITORY );
final var statefulDataRepository =
jakartaDataRepository && hasStatefulLifecycleMethods( element );
final var getter = findSessionGetter( element );
if ( getter != null ) {
// Never make a DAO for Panache subtypes
if ( !isPanacheType( element ) && !isQuarkusDataType( element ) ) {
repository = true;
sessionType = addRepositoryConstructor( getter );
}

That said maybe it doesn't hurt to copy annotations there too...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see why it would hurt any repository, native or Jakarta Data to respect @Transactional

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

I suppose if we don't want such annotations on other repositories (e.g. because they're not CDI beans and thus @Transactional won't have an effect anyway), we should rather report a warning/error when we notice these annotations on other repositories.

@sonarqubecloud

Copy link
Copy Markdown

@yrodiere

Copy link
Copy Markdown
Member

This is going to need a backport to 7.4. Do you want me to make the backport PR? There are conflicts, I've noticed.

You'll need a backport to 8.0 too.

Please open the PRs, especially if there are conflicts :)

@yrodiere

yrodiere commented Jul 24, 2026

Copy link
Copy Markdown
Member

@gavinking not merging yet in case you have an objection...

@gavinking

Copy link
Copy Markdown
Member

Yeah, I'm not sure this is quite right. Copying interceptor annotations only makes sense when we know the object is instantiated as a CDI bean, and that's a special case which only gets enabled when jakarta.enterprise.context is in the build path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants