|
8 | 8 | import org.checkerframework.checker.nullness.qual.Nullable; |
9 | 9 | import org.hibernate.AssertionFailure; |
10 | 10 | import org.hibernate.grammars.hql.HqlLexer; |
| 11 | +import org.hibernate.metamodel.mapping.ordering.OrderByFragmentTranslator; |
11 | 12 | import org.hibernate.metamodel.model.domain.EntityDomainType; |
12 | 13 | import org.hibernate.processor.Context; |
13 | 14 | import org.hibernate.processor.ImportContextImpl; |
|
20 | 21 | import org.hibernate.processor.util.TypeUtils; |
21 | 22 | import org.hibernate.processor.validation.ProcessorSessionFactory; |
22 | 23 | import org.hibernate.processor.validation.Validation; |
| 24 | +import org.hibernate.query.SyntaxException; |
23 | 25 | import org.hibernate.query.criteria.JpaEntityJoin; |
24 | 26 | import org.hibernate.query.criteria.JpaRoot; |
25 | 27 | import org.hibernate.query.criteria.JpaSelection; |
@@ -1232,6 +1234,30 @@ private void validatePersistentMembers(List<? extends Element> membersOfClass) { |
1232 | 1234 | if ( hasAnnotation(memberOfClass, MANY_TO_ONE, ONE_TO_ONE, ONE_TO_MANY, MANY_TO_MANY) ) { |
1233 | 1235 | validateAssociation(memberOfClass); |
1234 | 1236 | } |
| 1237 | + if ( hasAnnotation(memberOfClass, ORDER_BY) ) { |
| 1238 | + validateOrderBy( memberOfClass ); |
| 1239 | + } |
| 1240 | + } |
| 1241 | + } |
| 1242 | + |
| 1243 | + private void validateOrderBy(Element memberOfClass) { |
| 1244 | + final AnnotationMirror annotation = |
| 1245 | + castNonNull(getAnnotationMirror( memberOfClass, ORDER_BY)); |
| 1246 | + final AnnotationValue annotationValue = getAnnotationValue(annotation); |
| 1247 | + if ( annotationValue != null ) { |
| 1248 | + final String fragment = annotationValue.getValue().toString(); |
| 1249 | + if ( !fragment.isBlank() ) { |
| 1250 | + try { |
| 1251 | + OrderByFragmentTranslator.check( fragment ); |
| 1252 | + } |
| 1253 | + catch (SyntaxException e) { |
| 1254 | + final String message = "Error in ordering: " + e.getMessage(); |
| 1255 | + context.message( memberOfClass, annotation, annotationValue, message, Diagnostic.Kind.ERROR ); |
| 1256 | + } |
| 1257 | + catch (Exception ignored) { |
| 1258 | + // do nothing with it |
| 1259 | + } |
| 1260 | + } |
1235 | 1261 | } |
1236 | 1262 | } |
1237 | 1263 |
|
|
0 commit comments