Hi!
I firguring out how to write a finder method that returns one entity bean selected on a MAX creteria.
I have a report_id, and every update on the report, the version field is incremented. To get the latest report available in SQL it would be
SELECT MAX(version),(other fields needed) FROM Test WHERE Test.report_id = ..
* @jboss.query * query="SELECT OBJECT(o) FROM Test o WHERE o.report_id = ?1 AND o.version=MAX(o.version)" * signature="java.util.Collection findByLatestVersionReport_id(int report_id)"
SELECT OBJECT(o) FROM Test o WHERE o.report_id = ?1 AND o.version=( SELECT MAX(o.version) FROM Test o WHERE o.report_id=?1 )
I've found a workaround for now:
SELECT OBJECT(o) FROM Test o WHERE o.report_id =?1 ORDER BY o.log_id DESC LIMIT 1