I have a Hibernate mapped status class that holds multiple status entries for an entity, like...
Code:
public class EntityStatus {
private int OwningEntityID
private int StatusID
private java.util.Date StatusUpdated
}
OwningEntity Status ID StatusUpdated
-------------------------------------------
1 1 23/01/10
1 2 23/02/10
1 4 23/04/10
2 4 19/02/10
3 1 21/02/10
3 1 21/03/10
4 3 23/01/10
4 4 11/04/10
I'm struggling to define a valid HQL query that returns just the latest status entries for each owning entity based around the most recent 'StatusUpdated', something like..
Code:
from distinct m EntityStatus as m
where m.statusUpdated = (select max(n.statusUpdated) from EntityStatus as n where n.owningEntityID = m.owningEntityID)
The results should be...
Code:
OwningEntity Status ID StatusUpdated
-------------------------------------------
1 4 23/04/10
2 4 19/02/10
3 1 21/03/10
4 4 11/04/10
Any suggestions?