0

I have an entity and i'm using Pageable and I want to sort by a calculated property. here is my entity:

public class Task extends Entity implements Serializable {

  @JsonView(Views.Simple.class)
  private long startTime;

  @JsonView(Views.Simple.class)
  private long endTime;
}

In the repository I have :

Page<Task> findAll(Pageable pageable);

And in the service I want to sort by

endTime - StartTime

badr.zr
  • 1
  • 4
  • Hi and welcome to stackoverflow, please also add what you have tried so far and what did not work about this. Please refer to: https://stackoverflow.com/help/how-to-ask – Sven Hakvoort Oct 15 '18 at 10:35
  • Possible duplicate of [Spring Data JPA - Is it possible to sort on a calculated property?](https://stackoverflow.com/questions/37139985/spring-data-jpa-is-it-possible-to-sort-on-a-calculated-property) – Rahim Dastar Oct 15 '18 at 10:38
  • Possible duplicate of https://stackoverflow.com/questions/2370215/ordering-results-by-computed-value-in-hibernate – Michal Oct 15 '18 at 10:38
  • thanks @Michal, this is a good solution but i don't want that the computed value to be persisted in the database. I added the @Transient annotation but, an exception is raised : `Unable to locate Attribute with the the given name [runTime] on this ManagedType` – badr.zr Oct 15 '18 at 11:25

0 Answers0