Hello,
I have a question concerning HQL. In my model I have:
- a Sale entity which has n SaleHistoryEntries.
- each SaleHistoryEntry is associated to a status and has a date.
- a Status has a code name (TREATED, IN_TRANSIT, COMPLETED, CANCELED, etc.)
For example:
Code:
Sale A => SaleHistoryEntry (2008-01-01) => TREATED
=> SaleHistoryEntry (2008-01-02) => IN_TRANSIT
=> SaleHistoryEntry (2008-01-03) => COMPLETED
Sale B => SaleHistoryEntry (2008-01-01) => TREATED
=> SaleHistoryEntry (2008-01-02) => CANCELED
Sale C => SaleHistoryEntry (2008-01-01) => TREATED
=> SaleHistoryEntry (2008-01-02) => IN_TRANSIT
Sale D => SaleHistoryEntry (2008-01-01) => TREATED
=> SaleHistoryEntry (2008-01-02) => COMPLETED
I would like to make a HQL request to get all the Sales that are in a certain state (that is that their latest SaleHistoryEntry has a particular Status.
For example (using the previous model example). I would like to fetch the Sales that are currently in the COMPLETED state. I should therefore receive A and D.
I have read the HQL documentation and have tried a few things but I don't know how to retrieve the latest of the SaleHistoryEntries of the sale.
Any idea or clue would be greatly appreciated. At the limit, I could put a currentStatus flag on the SaleHistoryEntry but I don't believe I should need that.
Thanks for any help,
Francois