我正在使用Hibernate Envers进行审核。它工作正常。但是,我试图在修改数据后立即获得rev id。我有CustomRevisionEntity如下:
import javax.persistence.Entity;
import org.hibernate.envers.DefaultRevisionEntity;
import org.hibernate.envers.RevisionEntity;
@Entity
@RevisionEntity(CustomRevisionListener.class)
public class CustomRevisionEntity extends DefaultRevisionEntity {
private static final long serialVersionUID = 3775550420286576001L;
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
和CustomRevisionListener:
import org.golf.repository.domain.entity.CustomRevisionEntity;
import org.hibernate.envers.RevisionListener;
public class CustomRevisionListener implements RevisionListener {
public void newRevision(Object revisionEntity) {
CustomRevisionEntity revision = (CustomRevisionEntity) revisionEntity;
revision.setUsername("username"); // For testing
}
}
那么,当例如更新地址如下所示,如何获得rev id?
public class TestClass {
updateAddress(address);
// how to get rev id here?
}
谢谢!
答案 0 :(得分:1)
revision.setRevId(RevMapper.getRevId());
的内容,RevMapper是包含静态属性revId,getter和setter的类。因此,在TestClass中,您需要使用RevMapper.setRevId(id);
设置revId
上面只是一个简单的解释,您需要考虑如何生成revId等。