javax.persistence.criteria.Order.reverse() method javadoc explicitly declares:
public interface Order {
/**
* Switch the ordering.
* @return a new <code>Order</code> instance with the reversed ordering
*/
Order reverse();
This interface is implemented by two classes: 1. In master branch (5.4.x versions) - by org.hibernate.query.criteria.internal.OrderImpl with this implementation:
...
public Order reverse() {
ascending = !ascending;
return this;
}
...
It returns this instead of new object 2. In wip/6.0 branch there is another class org.hibernate.query.sqm.tree.select.SqmSortSpecification that has the same problem:
@Override
public JpaOrder reverse() {
this.sortOrder = this.sortOrder == null ? SortOrder.DESCENDING : sortOrder.reverse();
return this;
}
Proposal: respect the contract and return new created object. |