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?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @mbellade that we should dig a bit deeper into this, via the test case given here: https://github.com/lukaseckert/hibernate-test-case-HHH-19020/tree/main/orm.

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"

I think you know what I think of the idea of taking at face value any claim made by a user in an issue report. :)

Copy link
Member Author

@jrenaat jrenaat Aug 13, 2025

Choose a reason for hiding this comment

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

My findings:

062afdb6cda9fe359740b0ed4aad2a1a3b83fc15 is the first bad commit
commit 062afdb6cda9fe359740b0ed4aad2a1a3b83fc15 (HEAD)
Author: Marco Belladelli <marcobladel@gmail.com>
Date:   Thu May 23 11:46:59 2024 +0200

    HHH-18103 Correct metamodel for embeddables with a mapped superclass

@mbellade thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Before my fix, the metamodel for embeddables extending from mapped superclasses was simply wrong (the attributes were not considered as defined by the superclass).

That doesn't give me much context as to why the mapped superclass might be null, though. As I said in my previous comment, it would be nice to understand the cause of it as there might be a bug there - I can take a look at the issue and try isolating a test case if you're having trouble with that.

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