Skip to content

HHH-19020 - provide more info in case a declared MappedSuperclass is not found #10739

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 1 commit into
base: main
Choose a base branch
from

Conversation

jrenaat
Copy link
Member

@jrenaat jrenaat commented Aug 11, 2025


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

…not found

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
@jrenaat jrenaat requested a review from gavinking August 11, 2025 20:29
@@ -274,6 +275,9 @@ public static void addPropertyToMappedSuperclass(
ClassDetails declaringClass,
MetadataBuildingContext context) {
final MappedSuperclass superclass = context.getMetadataCollector().getMappedSuperclass( declaringClass.toJavaClass() );
if ( superclass == null ) {
throw new HibernateException( "Mapped superclass is null for declaring type " + declaringClass );
Copy link
Member

Choose a reason for hiding this comment

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

This message is slightly better than an NPE, but it doesn't really tell the user what they did wrong, nor what they should do to fix it.

Also, shouldn't it be a MappingException?

Copy link
Member

Choose a reason for hiding this comment

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

I think we might want to understand why the superclass is null, too, since looking at the code-path that leads here (from the Jira's stack trace) it looks like we're processing an embeddable that extends from a @MappedSuperclass. I fear that we might be processing the embeddable before its parent, I remember fixing something similar for https://hibernate.atlassian.net/browse/HHH-18103.

Copy link
Member Author

@jrenaat jrenaat Aug 12, 2025

Choose a reason for hiding this comment

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

I think we might want to understand why the superclass is null, too, since looking at the code-path that leads here (from the Jira's stack trace) it looks like we're processing an embeddable that extends from a @MappedSuperclass. I fear that we might be processing the embeddable before its parent, I remember fixing something similar for https://hibernate.atlassian.net/browse/HHH-18103.

One of the issue's comments states "the superclass of the embedded id was not part of the mapped resources that Spring registers with Hibernate", so it seems like this was an error in Spring, and this was just an attempt to cater for the user's - I think correct - request for more useful (than an NPE) info on what happened.
@gavinking This is also why I chose to throw a more generic HibernateException, since we may not be sure what the cause of the missing MappedSuperclass is?

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