I am using envers to audit my stored data. I can easily get data for each audited entity using auditReader. For ABC as my object
List<ABC> revisions = auditReader.createQuery()
.forRevisionsOfEntity(ABC.class, true, false)
.add(AuditEntity.revisionProperty("timestamp").ge(Instant.now().minusSeconds(86400).toEpochMilli()))
.add(AuditEntity.revisionProperty("timestamp").le(Instant.now().plusSeconds(86400).toEpochMilli()))
.getResultList();
Will return all objects from yesterday to tomorrow. Now I wanted to get all the revisions with date and I have no clue how to do that.
I tried to create DTO, like
MyDto { long timestamp; ABC abc; } or MyDto{ long timestamp; allOther variables} with @Data annotation.
String queryString = "SELECT schema.revinfo.revtstmp, schema.abc_aud.id, schema.abc_aud.variable1, schema.abc_aud.variable2 FROM schema.revinfo " +
"INNER JOIN schema.abc_aud ON schema.abc_aud.rev = schema.revinfo.rev";
Query query = entityManager.createNativeQuery(queryString);
List<MyDto> list = (List<MyDto>) query.getResultList();
But I get class cast exception, and to be honest looks terrible.
I was thinking about using repos from Spring Data but... aud tables are not mapped as entities in java code.
I do not have any other ideas, how to approach this problem
question from:
https://stackoverflow.com/questions/65844151/get-revision-object-with-revision-timestamp-hibernate-envers 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…