Skip to content

Fix HHH-19076 #10281

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix HHH-19076 #10281

wants to merge 2 commits into from

Conversation

mensinda
Copy link
Contributor

@mensinda mensinda commented Jun 4, 2025

This commit fixes HHH-19076. This bug is not trivial to reproduce since it requires a very specific entity setup:

  • There must be at least 2 entities
  • Both entities must extend the same @MappedSuperclass
  • The @MappedSuperclass must have an @Id
  • One (and only one) of the entities must additionally use @IdClass
  • The entities must be named / loaded / etc. so that the entity WITHOUT the @IdClass is processed first

Specifically the last step is impossible to reproduce reliably, since it depends on the order hibernate processes the entities, which in turn depends on the order of the values of a map entityBindingMap.

Depending on the order the entities are processed, the MetadataContext.mappedSuperClassTypeToPersistentClass map stores for the shared @MappedSuperclass a different entity.
However, to correctly process the attributes of the @MappedSuperclass, the entity with the @IdClass must be used in resolveVirtualIdentifierMember.

To fix this, this commit changes the simple mappedSuperClassTypeToPersistentClass map to store a set
of entities instead of only the first encountered entity.
Next, the resolveVirtualIdentifierMember function uses the first matching entity of this set.


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.


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

@mensinda mensinda changed the title Fix hhh 19076 Fix HHH-19076 Jun 4, 2025
This commit fixes HHH-19076. This bug is not trivial to reproduce
since it requires a very specific entity setup:

- There must be at least 2 entities
- Both entities must extend the same @MappedSuperclass
- The @MappedSuperclass must have an @id
- One (and only one) of the entities must additionally use @IdClass
- The entities must be named / loaded / etc. so that the entity WITHOUT the @IdClass is processed first

Specifically the last step is impossible to reproduce reliably, since it depends
on the [order hibernate processes the entities][1], which in turn depends on the
order of the values of [a map `entityBindingMap`][2].

Depending on the order the entites are processed, the
[`MetadataContext.mappedSuperClassTypeToPersistentClass`][3] map
stores for the shared @MappedSuperclass a different entity. However,
to correctly process the attributes of the @MappedSuperclass, the
entity with the @IdClass must be used in [`resolveVirtualIdentifierMember`][4].

To fix this, this commit changes the simple
[`mappedSuperClassTypeToPersistentClass`][3] map to store a set
of entities instead of only the first encountered entity. Next,
the [`resolveVirtualIdentifierMember`][4] function uses the first
matching entity of this set.

[1]: https://github.com/hibernate/hibernate-orm/blob/3cfeb8fa29769258a0c0615b7e14b469798f0f3a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java#L627-L629
[2]: https://github.com/hibernate/hibernate-orm/blob/3cfeb8fa29769258a0c0615b7e14b469798f0f3a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataImpl.java#L86
[3]: https://github.com/hibernate/hibernate-orm/blob/3cfeb8fa29769258a0c0615b7e14b469798f0f3a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java#L96
[4]: https://github.com/hibernate/hibernate-orm/blob/3cfeb8fa29769258a0c0615b7e14b469798f0f3a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java#L687
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