|
29 | 29 | import jakarta.persistence.criteria.From;
|
30 | 30 | import jakarta.persistence.criteria.Join;
|
31 | 31 | import jakarta.persistence.criteria.JoinType;
|
| 32 | +import jakarta.persistence.criteria.Nulls; |
32 | 33 | import jakarta.persistence.criteria.Path;
|
33 | 34 | import jakarta.persistence.metamodel.Attribute;
|
34 | 35 | import jakarta.persistence.metamodel.Attribute.PersistentAttributeType;
|
@@ -720,18 +721,25 @@ private static jakarta.persistence.criteria.Order toJpaOrder(Order order, From<?
|
720 | 721 | PropertyPath property = PropertyPath.from(order.getProperty(), from.getJavaType());
|
721 | 722 | Expression<?> expression = toExpressionRecursively(from, property);
|
722 | 723 |
|
723 |
| - if (order.getNullHandling() != Sort.NullHandling.NATIVE) { |
724 |
| - throw new UnsupportedOperationException("Applying Null Precedence using Criteria Queries is not yet supported."); |
725 |
| - } |
| 724 | + Nulls nulls = toNulls(order.getNullHandling()); |
726 | 725 |
|
727 | 726 | if (order.isIgnoreCase() && String.class.equals(expression.getJavaType())) {
|
728 | 727 | Expression<String> upper = cb.lower((Expression<String>) expression);
|
729 |
| - return order.isAscending() ? cb.asc(upper) : cb.desc(upper); |
| 728 | + return order.isAscending() ? cb.asc(upper, nulls) : cb.desc(upper, nulls); |
730 | 729 | } else {
|
731 |
| - return order.isAscending() ? cb.asc(expression) : cb.desc(expression); |
| 730 | + return order.isAscending() ? cb.asc(expression, nulls) : cb.desc(expression, nulls); |
732 | 731 | }
|
733 | 732 | }
|
734 | 733 |
|
| 734 | + private static Nulls toNulls(Sort.NullHandling nullHandling) { |
| 735 | + |
| 736 | + return switch (nullHandling) { |
| 737 | + case NULLS_LAST -> Nulls.LAST; |
| 738 | + case NULLS_FIRST -> Nulls.FIRST; |
| 739 | + case NATIVE -> Nulls.NONE; |
| 740 | + }; |
| 741 | + } |
| 742 | + |
735 | 743 | static <T> Expression<T> toExpressionRecursively(From<?, ?> from, PropertyPath property) {
|
736 | 744 | return toExpressionRecursively(from, property, false);
|
737 | 745 | }
|
|
0 commit comments