I currently have a system in place which can filter and sort records in the database and return them as a Paged object. One of the lines is like this:
final
Assume that you have entity with a String
filed and you want to sort it like Long
with jpa Pageable.
So you need to do following things:(Remember this only works with Oracle Database)
Long
type@Formula
in getter method and evoke to_number()
@Entity public class testEntity{ private String oldField; //Getter and Setter private Long newField; //Setter @Formula(value = "to_number(oldField)") public Long getNewField() { return newField; } }
newfiled
if (Objects.nonNull(pagingRequest.getSort()) && pagingRequest.getSort().getFieldName().equals("oldField")) { pagingRequest.getSort().setFieldName("newField"); }