Basically we have a one to many relationship between two tables. We need to grab the records from the master table in the order of the maximum value of a date field in the child table grouped by the primary key of the master table and process the records in that order.
The solution that I posted earlier works but there are a lot of database calls. I would prefer one call.
The query that ends up being produced by hiberbate looks something like this:
Code:
SELECT
table1.field1 as fld1, max(table2.dateField) as mxFld
FROM
table1 INNER JOIN table2 ON table1.field1 = table2.tbl1Field1
GROUP BY
fld1
ORDER BY
mxFld;
Then I loop through the results and take the value from field1 and query the database to produce the pojo model of table1.