Skip to content

HHH-20582 Walk superclass auditing data when resolving @OneToOne mappedBy#12792

Open
brodziakm wants to merge 2 commits into
hibernate:mainfrom
brodziakm:HHH-20582-toone-mappedby-superclass
Open

HHH-20582 Walk superclass auditing data when resolving @OneToOne mappedBy#12792
brodziakm wants to merge 2 commits into
hibernate:mainfrom
brodziakm:HHH-20582-toone-mappedby-superclass

Conversation

@brodziakm

@brodziakm brodziakm commented Jun 17, 2026

Copy link
Copy Markdown

Fixes https://hibernate.atlassian.net/browse/HHH-20582

Envers ToOneRelationMetadataGenerator.checkMappedByAudited (added in HHH-19897 / PR #11175)
validates that the owning side of an inverse @OneToOne is audited, but only inspects the
concrete referenced entity's ClassAuditingData. CollectionMappedByResolver was updated in
the same change to walk superclasses; this brings @OneToOne inverse resolution in line.
Adds MappedByOnSuperclassOneToOneTest reproducing bootstrap failure when mappedBy targets
a property declared on a parent @Entity in a SINGLE_TABLE hierarchy.


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-20582 (Bug):

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

@mbellade mbellade left a comment

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.

Thanks @brodziakm, the fix is looking great. I've added a few suggestions on the test side.

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.

I know you copied this from the "negative" tests of https://github.com/hibernate/hibernate-orm/pull/11175/changes#diff-4133702339842d4a59cbeeb04c398c116f8bd63c758b9a1eb71bb98ded6acc1a, which is fine, but since we expect this case to work correctly it would be better to use the @EnversTest + @Jpa(annotatedClasses={...}) annotations, and actually persist some entities and verify the mappings and audit trail work as expected.

Comment on lines 47 to 54

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.

Please use explicit entity names for inner class entities and avoid GenerationType.IDENTITY as that is not supported across all dbs.

Suggested change
@Entity(name = "Account")
@Audited
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public abstract static class Account {
@Id
@GeneratedValue

Comment on lines 58 to 66

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.

Same as above:

Suggested change
@Entity(name = "Credential")
@Audited
@Table(name = "credential")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type")
public abstract static class Credential {
@Id
@GeneratedValue

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.

Same as above:

Suggested change
@Entity(name = "PasswordCredential")

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.

Same as above:

Suggested change
@Entity(name = "User")

@hibernate-github-bot

hibernate-github-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@brodziakm brodziakm force-pushed the HHH-20582-toone-mappedby-superclass branch 2 times, most recently from c731a80 to 95055b0 Compare June 18, 2026 22:41
@brodziakm brodziakm force-pushed the HHH-20582-toone-mappedby-superclass branch from 95055b0 to e8b56ee Compare June 25, 2026 03:58
@brodziakm

Copy link
Copy Markdown
Author

Thanks @mbellade - I've addressed the PR feedback. Could you take another look when you have a moment? CI may need workflow approval to get further, I'm a first-time contributor.

@brodziakm brodziakm force-pushed the HHH-20582-toone-mappedby-superclass branch from e8b56ee to 023d505 Compare June 25, 2026 04:15
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.

2 participants