Skip to content

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

Merged
merged 2 commits into from
Mar 31, 2025

Conversation

cigaly
Copy link
Contributor

@cigaly cigaly commented Mar 30, 2025

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.


@cigaly cigaly marked this pull request as draft March 30, 2025 15:31
@cigaly cigaly marked this pull request as ready for review March 30, 2025 21:03
final String sourceQualifiedName = qualifiedName.replace( '$', '.' );
final String sourceQualifiedName = removeDollar( qualifiedName );
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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().

Copy link
Contributor Author

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 mainwill 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)

Copy link
Member

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.

Copy link
Member

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() calls removeDollar(), 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
@gavinking
Copy link
Member

Looks like the test are passing, @cigaly, is there any reason to not just merge this as-is?

@cigaly
Copy link
Contributor Author

cigaly commented Mar 31, 2025

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.

@gavinking gavinking merged commit 2e5a7f8 into hibernate:main Mar 31, 2025
23 of 24 checks passed
@gavinking
Copy link
Member

OK, done, thanks once again man!

@cigaly
Copy link
Contributor Author

cigaly commented Mar 31, 2025

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 IdClass in inner class

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.

2 participants