Skip to content

HHH-19711 Improve mapped-by + join-column exception message with the full property path #10760

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

Conversation

dreab8
Copy link
Member

@dreab8 dreab8 commented Aug 14, 2025

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


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.


@dreab8 dreab8 requested a review from mbellade August 14, 2025 15:06
throw new AnnotationException(
String.format(
Locale.ROOT,
"Association '%s' is 'mappedBy=%s' a different entity and may not explicitly specify the '@JoinColumn'",
Copy link
Member

@gavinking gavinking Aug 14, 2025

Choose a reason for hiding this comment

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

Folks, I definitely appreciate the desire to improve error messages, but I think this change makes the message worse:

  1. ... is 'mappedBy=%s' a different entity doesn't read like a well-formed English sentence, and it's not even correct Java (it has missing quotes). If you really think it's important to include the name of the mapping attribute, it should be ... is 'mappedBy' the attribute '%s' of a different entity.
  2. If I'm not mistaken, I used getRelativePath() here very deliberately because I didn't want a long-ass qualified name right at the start of the exception message. That really harms readability of the message. When we include full-qualified names, we usually try to put them at the end of the error message.

Yes, I'm aware I'm being super-anal here.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps:

"Association '%s' of entity '%s' is 'mappedBy' a different entity and may not explicitly specify the '@JoinColumn'"

where the second %s is the (unqualified) entity name.

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