Skip to content
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

HHH-18764 Fix incorrect type resolution in ManyToOneType dirty check #9172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stringintech
Copy link

@stringintech stringintech commented Oct 26, 2024

This pull request addresses a bug in the isDirty method when dealing with ManyToOne associations that are referenced by a unique key instead of a primary key, particularly when the primary key is a custom type.

This bug stems from a mismatch in how isDirty checks for changes: while it correctly retrieves the unique key value using getIdentifier, it incorrectly relies on getIdentifierType, which only considers the primary key type. This results in unexpected behavior—in this case, a ClassCastException when attempting to call the custom ID type's equals method.

The fix replaces getIdentifierType with getIdentifierOrUniqueKeyType, ensuring that isDirty correctly accounts for both primary keys and unique keys. This issue is demonstrated in the unit test ManyToOneUniqueKeyReferenceWithCustomIdTest.


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-18764

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.

1 participant