Description
Akim Bassa opened DATAJPA-1198 and commented
org.springframework.data.jpa.repository.support.Querydsl#buildOrderPropertyPathFrom
always adds lower(...) to the sortPropertyExpression if order.isIgnoreCase is true, regardless of the type of the property which will get ordered.
When sorting e.g. a Timestamp, this leads to an exception in Postgresql 9.4.1212: o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: function lower(timestamp without time zone) does not exist.
org.springframework.data.jpa.repository.query.QueryUtils#toJpaOrder
in comparison does the same job but only adds lower(...) if the property is a String.
private Expression<?> buildOrderPropertyPathFrom(Order order) {
Assert.notNull(order, "Order must not be null!");
PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType());
Expression<?> sortPropertyExpression = builder;
while (path != null) {
// FIXME also check type here
if (!path.hasNext() && order.isIgnoreCase()) {
// if order is ignore-case we have to treat the last path segment as a String.
sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower();
} else {
sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment());
}
path = path.next();
}
return sortPropertyExpression;
}
private static javax.persistence.criteria.Order toJpaOrder(Order order, Root<?> root, CriteriaBuilder cb) {
PropertyPath property = PropertyPath.from(order.getProperty(), root.getJavaType());
Expression<?> expression = toExpressionRecursively(root, property);
if (order.isIgnoreCase() && String.class.equals(expression.getJavaType())) {
Expression<String> lower = cb.lower((Expression<String>) expression);
return order.isAscending() ? cb.asc(lower) : cb.desc(lower);
} else {
return order.isAscending() ? cb.asc(expression) : cb.desc(expression);
}
}
Expected solution:
Only add lower to sortPropertyExpression if sortPropertyExpression has type String
Affects: 1.11.8 (Ingalls SR8)
Attachments:
- image-2020-09-22-15-34-17-807.png (45.96 kB)
- image-2020-09-22-15-43-55-434.png (47.88 kB)
- image-2020-09-22-15-44-36-126.png (50.06 kB)
Issue Links:
- DATAJPA-1779 Querydsl buildOrderPropertyPathFrom generate SQL inconsistent for column not String
("is duplicated by") - DATAJPA-1780 Querydsl buildOrderPropertyPathFrom generate SQL inconsistent for column not String
("is duplicated by")
Referenced from: pull request #428
Backported to: 2.3.5 (Neumann SR5)
1 votes, 3 watchers