I have marked my entity @Audited
and I can see that it logs the revision number and timestamp of a new revision, but how can I add custom metadata? I believe it must be possible since org.springframework.data.RevisionMetadata
has the getDelegate()
method with the following Javadoc:
Returns the underlying revision metadata which might provider more detailed implementation specific information.
答案 0 :(得分:1)
从纯Hibernate Envers的角度来看,如果您希望修订实体存储有关修订的其他上下文信息,例如谁修改了实体或者可能是更改的原因,那么您可能希望通过{{1 } callback与RevisionListener
的自定义扩展相结合。
例如:
DefaultRevisionEntity
Envers将检测特殊注释的@Entity
@RevisionEntity(CustomRevisionListener.class)
public class CustomRevisionEntity extends DefaultRevisionEntity {
private String userName;
/* getter/setters */
}
public class CustomRevisionListener implements RevisionListener {
@Override
public void newRevision(Object revisionEntity) {
CustomRevisionEntity cre = (CustomRevisionEntity)revisionEntity;
cre.setUserName( UserContextHolder.getUserContext().getUserName() );
}
}
实体类并使用它。它还将检测指定的@RevisionEntity
实现,并在构造新的修订实体时实例化并回调此类。
不幸的是,我无法谈论这对于RevisionListener
和spring-data
项目如何转换使用方式。