Get previous version of entity in Hibernate Envers

后端 未结 5 1754
孤街浪徒
孤街浪徒 2021-01-31 22:36

I have an entity loaded by Hibernate (via EntityManager):

User u = em.load(User.class, id)

This class is audited by Hibernate Enve

5条回答
  •  攒了一身酷
    2021-01-31 23:42

    maybe this then (from AuditReader docs)

    AuditReader reader = AuditReaderFactory.get(entityManager);
    User user_rev1 = reader.find(User.class, user.getId(), 1);
    
    List revNumbers = reader.getRevisions(User.class, user_rev1);
    User user_previous = reader.find(User.class, user_rev1.getId(),
      revNumbers.get(revNumbers.size()-1));
    

    (I'm very new to this, not sure if I have all the syntax right, maybe the size()-1 should be size()-2?)

提交回复
热议问题