How do I create custom field to store user credentials in REVINFO table

六月ゝ 毕业季﹏ 提交于 2019-12-25 03:34:45

问题


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?


回答1:


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)


来源:https://stackoverflow.com/questions/30184227/how-do-i-create-custom-field-to-store-user-credentials-in-revinfo-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!