From the docs I know we can specify a column, but is there a way to pass in a custom comparator and sort according to that?
So it might look something like this:
@OneToMany(cascade=CascadeType.ALL)
@OrderBy("createdDateTime", comparator=StripYearComparator.class)
public List<A> getAs() {
return result;
}
Anyone had the same use case as me?
Not that I know of @Tommy. The whole point of the
@OrderByis to define how the sorting is being done by the database (or other datastore). It translates into a SQL query (or some other request) like as the following.The data is not retrieved and then sorted on the client by the driver or some other entity so there is no way to inject your own comparator.
If you need an alternative sorting strategy then I’m afraid you are going to have to retrieve the items into your code and sort them yourself.