|
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;
|
@@ -727,18 +728,25 @@ private static jakarta.persistence.criteria.Order toJpaOrder(Order order, From<?
|
727 | 728 | PropertyPath property = PropertyPath.from(order.getProperty(), from.getJavaType());
|
728 | 729 | Expression<?> expression = toExpressionRecursively(from, property);
|
729 | 730 |
|
730 |
| - if (order.getNullHandling() != Sort.NullHandling.NATIVE) { |
731 |
| - throw new UnsupportedOperationException("Applying Null Precedence using Criteria Queries is not yet supported."); |
732 |
| - } |
| 731 | + Nulls nulls = toNulls(order.getNullHandling()); |
733 | 732 |
|
734 | 733 | if (order.isIgnoreCase() && String.class.equals(expression.getJavaType())) {
|
735 | 734 | Expression<String> upper = cb.lower((Expression<String>) expression);
|
736 |
| - return order.isAscending() ? cb.asc(upper) : cb.desc(upper); |
| 735 | + return order.isAscending() ? cb.asc(upper, nulls) : cb.desc(upper, nulls); |
737 | 736 | } else {
|
738 |
| - return order.isAscending() ? cb.asc(expression) : cb.desc(expression); |
| 737 | + return order.isAscending() ? cb.asc(expression, nulls) : cb.desc(expression, nulls); |
739 | 738 | }
|
740 | 739 | }
|
741 | 740 |
|
| 741 | + private static Nulls toNulls(Sort.NullHandling nullHandling) { |
| 742 | + |
| 743 | + return switch (nullHandling) { |
| 744 | + case NULLS_LAST -> Nulls.LAST; |
| 745 | + case NULLS_FIRST -> Nulls.FIRST; |
| 746 | + case NATIVE -> Nulls.NONE; |
| 747 | + }; |
| 748 | + } |
| 749 | + |
742 | 750 | static <T> Expression<T> toExpressionRecursively(From<?, ?> from, PropertyPath property) {
|
743 | 751 | return toExpressionRecursively(from, property, false);
|
744 | 752 | }
|
|
0 commit comments