Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
702 views
in Technique[技术] by (71.8m points)

java - Get revision object with revision timestamp (Hibernate Envers)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...