Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
Spring Data Rest projection sorting

I have a projection for my entity and I need to sort it by field of inner class. This is part of my entities:

class Person {
    UUID guid;
    Set<DisabilityHistory> disabilityHistory;
}
class DisabilityHistory {
    Date createdDate;
}

I know about sort param but request like api/person/search?projection=myProjection&sort=disabilityHistory.createdDate,asc doesn't work. The only solution I have found is using @OrderBy annotation in my entity but in this case it will sorted always and I worried about performance.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This will not work as you are trying to sort an inner field in your entity, so you can't do it on DB level. The way I've used it is by sorting it in the Projection class using SpEL. This is an example of how you can do it:

@Projection(
        name = "sorted",
        types = Person.class
)
public interface PersonProjection {

    @Value("#{@personProjectionHelper.sortedByDisabilityHistory(target.disabilityHistory)}")
    List<DisabilityHistory> getDisabilityHistory();
}

And implement the sorting in Java:

@Component
public class PersonProjectionHelper {

    public List<DisabilityHistory> sortByDisabilityHistory(final List<DisabilityHistory> list) {
        // do the sorting on Java level
    }
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!