-
Notifications
You must be signed in to change notification settings - Fork 3.6k
HHH-19301 Must import FQCN when generating metamodel class for inner Jakarta Data repository interface #9938
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
Conversation
tooling/metamodel-generator/src/main/java/org/hibernate/processor/ClassWriter.java
Outdated
Show resolved
Hide resolved
final String sourceQualifiedName = qualifiedName.replace( '$', '.' ); | ||
final String sourceQualifiedName = removeDollar( qualifiedName ); |
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 change looks wrong to me. removeDollar()
removes a trailing dollar from a class name generated by Scott's tool for implementing query-by-method-name.
What we're trying to do here is replace a $
in the middle of a name of a class file corresponding to an inner class with a dot to get its name in the source code.
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.
Current code will change that trailing dollar to dot, and that is really bad thing :-)
Other solution can be something like
qualifiedName.substring( 0, qualifiedName.length() - 1 ).replace( '$', '.' ) + qualifiedName.charAt( qualifiedName.length() - 1 )
Not nice looking thing, but this will change all $
's into dots, except one at last position.
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.
Current code will change that trailing dollar to dot, and that is really bad thing :-)
Ah well I guess that's because TypeUtils.getGeneratedClassFullyQualifiedName()
should not be calling removeDollar()
.
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.
One solution is to skip importContext.importType( element.getQualifiedName().toString() )
if qualified (or simple name) is ending with $
. It will not be used in generated meta model class, anyway. This way only change from main
will be in AnnotationMetaEntity
:
if ( !element.getQualifiedName().toString().endsWith( "$" ) ) {
importContext.importType( element.getQualifiedName().toString() );
}
This will work fine with all existing tests, but will show that there is problem with dollar-ending inner class. This can be solved by not creating meta model class for injectable annotation meta entity that is not initialized (one not ending with dollar)
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'm not really sure what problem you're trying to solve here. The class names with trailing $
s are just a special case for the query by method name stuff. We're not expecting to encounter them in user code. I'm not even sure why getGeneratedClassFullyQualifiedName()
calls removeDollar()
, I don't think it should.
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'm not even sure why
getGeneratedClassFullyQualifiedName()
callsremoveDollar()
, I don't think it should.
Excuse me, I'm wrong, it is needed, because the test for that stuff fails without it.
…n.AnnotationMetaEntity constructor Not importing if FQCN ends with dollar sign
Looks like the test are passing, @cigaly, is there any reason to not just merge this as-is? |
I don't see any reason not to merge this. Guess that this is simplest solution. And other problem(s) are not connected with this one and should be fixed separately. |
OK, done, thanks once again man! |
You're welcome! BTW, can you, please, take a look at PR #9819 ? My assumption about property ordering was wrong, but real issue was use of generated composite |
Jira issue HHH-19301
Fully qualified name should be imported for inner (static) Jakarta Data repository interface
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.