Hibernate envers add audit column (username)
<p>Requirement is to add username column for every audit entry. </p>

<p>After googling a lot and going through the enverse docs I figured out how to implement it. I have implemented it as follows:</p>

<p>Implemented a revision listener:</p>

<pre><code>@Configurable
public class UserRevisionListener implements RevisionListener
{
    public void newRevision(Object revisionEntity)
    {
        UserRevEntity revision = (UserRevEntity) revisionEntity;
        String username = "";
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        Object principal = auth.getPrincipal();

        if (principal != null &amp;&amp; principal instanceof DepotUser)
            username = ((DepotUser) principal).getUsername();

        revision.setUsername(username);
    }
}
</code></pre>

<p>Create an entity class:</p>

<pre><code>@Entity
@Table(name = "USER_REV_ENTITY")
@RevisionEntity(UserRevisionListener.class)
public class UserRevEntity extends DefaultRevisionEntity
{
    private static final long   serialVersionUID    = 1L;
    private String              username;

    public String getUsername()
    {
        return username;
    }

    public void setUsername(String username)
    {
        this.username = username;
    }
}
</code></pre>

<p>I have referred a link that has an example of the same "<a href="http://thinkinginsoftware.blogspot.com/2011/03/auditing-entities-with-hibernate-jpa.html" rel="nofollow">Thinking in Software</a> ".</p>

<p>Default auditing is working fine.</p>

<p>Firstly, the table for the audit revision with the new username column should get auto generated (<strong>I think!</strong>). Its not getting generated.</p>

<p>So, I tried by creating the table and adding the table mapping in <strong>UserRevEntity</strong>. But no luck.</p>

<p>Can anyone help my identifying the issue?</p>

<p>Thanks, in advance.</p>