user2586917
user2586917

Reputation: 774

HQL for this entity model?

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

enter image description here

What would be the HQL query to get the latest (by accessTime) Audit record for each distinct Repository?

Thanks

Upvotes: 0

Views: 65

Answers (1)

bitkot
bitkot

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

Related Questions