Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda