[英]How do I create custom field to store user credentials in REVINFO table
We are using hibernate-envers and having *_AUD table that stores historical state of entities. 我们正在使用hibernate-envers,并具有用于存储实体历史状态的* _AUD表。 There is also a global REVINFO table which contains revision number, timestamp.
还有一个全局REVINFO表,其中包含修订号,时间戳。
I need to add user as field in REVINFO table. 我需要在REVINFO表中将用户添加为字段。 How to add "user" field in REVINFO table?
如何在REVINFO表中添加“用户”字段?
You can definitely create your custom RevisionInfo entity. 您绝对可以创建自定义的RevisionInfo实体。 The custom revisions entity must have an integer-valued unique property (preferably the primary id) annotated with {@link RevisionNumber} and a long-valued property annotated with {@link RevisionTimestamp}.
自定义修订版本实体必须具有用{@link RevisionNumber}注释的整数值唯一属性(最好是主ID)和用{@link RevisionTimestamp}注释的长值属性。
The {@link DefaultRevisionEntity} already has those two fields, so you may extend it, but you may also write your own revision entity from scratch. {@link DefaultRevisionEntity}已经具有这两个字段,因此您可以对其进行扩展,但是也可以从头开始编写自己的修订实体。 So in your case the revision entity may look like following:
因此,在您的情况下,修订版实体可能如下所示:
@Entity
@RevisionEntity()
public class RevisionsInfo extends DefaultRevisionEntity {
private Long userId;
public Long getUserId() { return userId; }
public void setUserId(final Long uid) { this.userId = uid; }
}
In addition to that you can also give your custom RevisionListener for any other special needs . 除此之外,您还可以为其他任何特殊需求提供自定义的RevisionListener。 See following example:
请参见以下示例:
public class RevisionListener implements org.hibernate.envers.RevisionListener
{
/**
* {@inheritDoc}
*/
public void newRevision(final Object revisionInfo)
{
// updateInfo your info here if required
}
}
The custom RevisionListener can be provided as an argument to RevisionEntity annotation. 可以将自定义RevisionListener作为RevisionEntity批注的参数提供。
@RevisionEntity(RevisionListener.class)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.