如何创建自定义字段以将用户凭证存储在REVINFO表中 [英] How do I create custom field to store user credentials in REVINFO table

查看:343
本文介绍了如何创建自定义字段以将用户凭证存储在REVINFO表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用hibernate-envers并具有存储实体历史状态的* _AUD表。还有一个全球性的REVINFO表,其中包含版本号,时间戳。



我需要在REVINFO表中添加用户字段。如何在REVINFO表中添加user字段?

解决方案

您可以创建自定义的RevisionInfo实体。自定义修订实体必须具有用{@link RevisionNumber}注释的整数值唯一属性(最好是主ID)和用{@link RevisionTimestamp}注释的长值属性。



DefaultRevisionEntity已经有了这两个字段,所以你可以扩展它,但是你也可以从头开始编写自己的修订实体。所以在你的情况下,修订实体可能如下所示:



  @Entity 
@RevisionEntity()
public class RevisionsInfo extends DefaultRevisionEntity {
$ b $ private private userId;

public Long getUserId(){return userId; }

public void setUserId(final Long uid){this.userId = uid; }

$ b

除此之外,您还可以为您的自定义修订侦听器对于任何其他特殊需求。参见下面的例子:
$ b

  public class RevisionListener implements org.hibernate.envers.RevisionListener 
{
/ **
* {@inheritDoc}
* /
public void newRevision(final Object revisionInfo)
{
// updateInfo your info here如果需要的话




$ b

自定义的RevisionListener可以作为参数提供
$ b

  @RevisionEntity(RevisionListener.class)


We are using hibernate-envers and having *_AUD table that stores historical state of entities. There is also a global REVINFO table which contains revision number, timestamp.

I need to add user as field in REVINFO table. How to add "user" field in REVINFO table?

解决方案

You can definitely create your custom RevisionInfo entity. 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}.

The {@link DefaultRevisionEntity} already has those two fields, so you may extend it, but you may also write your own revision entity from scratch. 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 . 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.

@RevisionEntity(RevisionListener.class)

这篇关于如何创建自定义字段以将用户凭证存储在REVINFO表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆