I have 2 tables say Parent and Child and they are one-to-many relationships.
In the entity classes, the Parent class has a list of Child objects.
So if using JPA query, how can I write a query to retrieve all Parent(s) and their last child?
There may be a case that a Parent does not have a child.
If using sql, it would be like:
select * from parent p
left outer join child c on c.parent_id = p.id
where c.child_id is null
or c.child_id = (
select child_id from (
select child_id
from child d
where d.parent_id = p.id order by child_age DESC, child_id DESC)
where rownum<=1)