-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19629 Hibernate Processor may fail when repository method parameter has more than one annotation (e.g. multiple constraints) / HHH-19630 Hibernate Processor may fail if the return type is a single entity and annotatated with multiple annotations #10595
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?
HHH-19629 Hibernate Processor may fail when repository method parameter has more than one annotation (e.g. multiple constraints) / HHH-19630 Hibernate Processor may fail if the return type is a single entity and annotatated with multiple annotations #10595
Conversation
It is working, with that comment that parameter will be annotated with two |
And if you really want some nitpicking, maybe you can (in
into else branch (when type is |
f4a1451
to
774bbfb
Compare
String result; | ||
if ( type instanceof DeclaredType dt ) { | ||
// get the "fqcn" without any type arguments | ||
result = dt.asElement().toString(); |
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've been avoiding the use of toString()
for this, since the Javadoc doesn't clearly say it's the qualified name, and there are more things than javac
.
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.
What I mean is, I would prefer to see TypeElement.getQualifiedName()
here.
It's obnoxious that there is no DeclaredType.getQualifiedName()
method, and that DeclaredType.getElement()
doesn't return a TypeElement
.
774bbfb
to
c345a55
Compare
if ( type instanceof DeclaredType dt && dt.asElement() instanceof TypeElement te ) { | ||
// get the "fqcn" without any type arguments | ||
String result = te.getQualifiedName().toString(); | ||
// add the < ? ,? ....> as necessary: | ||
if ( !dt.getTypeArguments().isEmpty() ) { | ||
result += dt.getTypeArguments().stream() | ||
.map( arg -> typeAsString( arg, true ) ) | ||
.collect( Collectors.joining( ", ", "<", ">" ) ); | ||
} | ||
if ( includeAnnotations ) { | ||
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) { | ||
result = annotation.toString() + ' ' + result; | ||
} | ||
} | ||
return result; | ||
} |
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.
Maybe will be better to use StringBuilder
. I guess that this will reduce amount of job for garbage collector.
if ( type instanceof DeclaredType dt && dt.asElement() instanceof TypeElement te ) { | |
// get the "fqcn" without any type arguments | |
String result = te.getQualifiedName().toString(); | |
// add the < ? ,? ....> as necessary: | |
if ( !dt.getTypeArguments().isEmpty() ) { | |
result += dt.getTypeArguments().stream() | |
.map( arg -> typeAsString( arg, true ) ) | |
.collect( Collectors.joining( ", ", "<", ">" ) ); | |
} | |
if ( includeAnnotations ) { | |
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) { | |
result = annotation.toString() + ' ' + result; | |
} | |
} | |
return result; | |
} | |
if ( type instanceof DeclaredType dt && dt.asElement() instanceof TypeElement te ) { | |
final StringBuilder sb = new StringBuilder(); | |
if ( includeAnnotations ) { | |
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) { | |
sb.append( annotation.toString() ).append( ' ' ); | |
} | |
} | |
// get the "fqcn" without any type arguments | |
sb.append( te.getQualifiedName().toString() ); | |
// add the < ? ,? ....> as necessary: | |
if ( !dt.getTypeArguments().isEmpty() ) { | |
sb.append( '<' ); | |
dt.getTypeArguments() | |
.forEach( arg -> sb.append( typeAsString( arg, true ) ) ); | |
sb.append( '>' ); | |
} | |
return sb.toString(); | |
} |
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.
@@ -2452,7 +2453,7 @@ private void createSingleParameterFinder( | |||
new CriteriaFinderMethod( | |||
this, method, | |||
methodName, | |||
returnType.toString(), | |||
typeAsString( returnType, false ), |
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.
@marko-bekhta there are three places in AnnotationMetaEntity
where this constructor is called. I believe this change should be replicated to all three invocations, do you agree?
https://hibernate.atlassian.net/browse/HHH-19629
https://hibernate.atlassian.net/browse/HHH-19630
cc: @cigaly
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.