Hibernate Criteria: Sort list by highest date of a child object

Asked

Viewed 22 times

0

How do I create a Criteria to list an object ordering by the longest date of a child object. In this scenario:

Domain:

class Entity {
    List<Children> childrens;
}

class Children {
    Date date
}

Something like this in SQL:

SELECT 
    *
FROM 
    entity
INNER JOIN 
    children c1 ON c1.entity_id = entity.id
WHERE 
    c1.date = 
        (SELECT MAX(c2.date) FROM children c2 WHERE c2.entity_id = c1.entity_id) 
ORDER BY 
    c1.date DESC
  • you are using pure Jdbc, Ibernate, springboot or what?

  • Hibernate Criteria (https://www.devmedia.com.br/hibernate-api-criteria-realizingconsultations/29627)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.