1

I used Spring 3.1, JPA 2 and Spring Data JPA(Hibenrate 4.1) in my project, and used Hibernate Envers(shipped with Hibernate 4) to audit some properties, I want to store the current logged in user in the related rev table, how to implement this? Thanks.

4

1 回答 1

3

您将需要创建自定义 Envers 列表器,如下所示

public class CustomEnversListener implements RevisionListener {
@Override
    public void newRevision(Object revisionEntity) {
       CustomRevisionEntity customRevisionEntity = (customRevisionEntity)revisionEntity;
       Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
       customRevisionEntity.setUsername(authentication.getName());
    }
}

有关更多信息,请查看 hibernate wiki

于 2012-08-01T05:15:31.593 回答