-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
base: main
Are you sure you want to change the base?
Conversation
…not found Signed-off-by: Jan Schatteman <[email protected]>
@@ -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 ); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. :)
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