Reputation: 774
Given the following entity one-to-many model:
One Repository can be linked to many AuditRecords.
Many Audit records can all link to the same AuditRecord
What would be the HQL query to get the latest (by accessTime) Audit record for each distinct Repository?
Thanks
Upvotes: 0
Views: 65
Reputation: 4504
I have done it once and I don't have access to that code now. This will give you latest AuditRecords
and then you can access Repository
from it. I create this with what I remember so...
select ar from AuditRecord ar
where ar.accessTime = (select max(ari.accessTime) from AuditRecord ari where ari.repositoryId = ar.repositoryId)
Upvotes: 1