Search code examples
hibernateauditdatabase-partitioning

AuditQuery Hibernate add order by partition


I have AuditQuery and I want to add order by with partition by.

like I have :

final AuditReader reader = AuditReaderFactory.get(em);
final List<Test> result = new ArrayList<Test>();

final AuditQuery query =
    reader.createQuery().forRevisionsOfEntity(Test.class, false, true);

and I would like to do something like :

ORDER by (MAX(VALUE) OVER (PARTITION BY ID ORDER BY ID))

how to do it in AuditQuery ?


Solution

  • AuditQuery is built on top of Hibernate Criteria, so it doesn't support window functions, in which case you need to write a native SQL.