fix for Bean Validation annotations on @Query method parameters
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
af3b9f011b
commit
427de60322
|
@ -5,6 +5,8 @@ import jakarta.data.repository.Find;
|
|||
import jakarta.data.repository.Query;
|
||||
import jakarta.data.repository.Repository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -15,10 +17,10 @@ public interface Bookshop extends CrudRepository<Book,String> {
|
|||
List<Book> byPublisher(String publisher_name);
|
||||
|
||||
@Query("select isbn where title like ?1 order by isbn")
|
||||
String[] ssns(String title);
|
||||
String[] ssns(@NotBlank String title);
|
||||
|
||||
@Query("select count(this) where title like ?1 order by isbn")
|
||||
long count1(String title);
|
||||
long count1(@NotNull String title);
|
||||
|
||||
@Query("select count(this) where this.title like ?1 order by this.isbn")
|
||||
long count2(String title);
|
||||
|
|
|
@ -2562,6 +2562,16 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
|||
}
|
||||
}
|
||||
|
||||
private static String stripTypeAnnotations(String argType) {
|
||||
while ( argType.startsWith("@") ) {
|
||||
int index = argType.indexOf(' ');
|
||||
if (index>0) {
|
||||
argType = argType.substring(index+1);
|
||||
}
|
||||
}
|
||||
return argType;
|
||||
}
|
||||
|
||||
private void checkNamedParameter(
|
||||
SqmParameter<?> param, List<String> paramNames, List<String> paramTypes, ExecutableElement method,
|
||||
AnnotationMirror mirror, AnnotationValue value, String queryParamType) {
|
||||
|
@ -2584,7 +2594,8 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean isLegalAssignment(SqmParameter<?> param, String argType, String queryParamType) {
|
||||
private static boolean isLegalAssignment(SqmParameter<?> param, String argumentType, String queryParamType) {
|
||||
final String argType = stripTypeAnnotations(argumentType);
|
||||
return param.allowMultiValuedBinding()
|
||||
? isLegalAssignment(argType, LIST + '<' + queryParamType + '>')
|
||||
: isLegalAssignment(argType, queryParamType);
|
||||
|
@ -2636,7 +2647,12 @@ public class AnnotationMetaEntity extends AnnotationMeta {
|
|||
private String typeAsString(TypeMirror type) {
|
||||
String result = type.toString();
|
||||
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) {
|
||||
result = result.replace(annotation.toString(), "");
|
||||
final String annotationString = annotation.toString();
|
||||
result = result
|
||||
// if it has a space after it, we need to remove that too
|
||||
.replace(annotationString + ' ', "")
|
||||
// just in case it did not have a space after it
|
||||
.replace(annotationString, "");
|
||||
}
|
||||
for ( AnnotationMirror annotation : type.getAnnotationMirrors() ) {
|
||||
result = annotation.toString() + ' ' + result;
|
||||
|
|
Loading…
Reference in New Issue