title: Creating Envers custom revision entity
body: <p>I'm trying to setup audit for our project.
  I started from the default configuration which works fine.</p>
  
  <p>The next step is to store the user which has made changes.
  Following the manual I created custom entity revision:</p>
  
  <pre><code>package com.csbi.samples.utils.audit;
  
  import java.io.Serializable;
  import java.text.DateFormat;
  import java.util.Date;
  
  import org.hibernate.envers.RevisionNumber;
  import org.hibernate.envers.RevisionTimestamp;
  import org.hibernate.envers.RevisionEntity;
  
  import javax.persistence.Id;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Entity;
  import javax.persistence.Table;
  import javax.persistence.Transient;
  
  @Entity
  @Table(name="REVISIONS")
  @RevisionEntity(CustomRevisionListener.class)
  public class CustomRevisionEntity implements Serializable {
  private static final long serialVersionUID = -1255842407304508513L;
  
  @Id
  @GeneratedValue
  @RevisionNumber
  private int id;
  
  @RevisionTimestamp
  private long timestamp;
  
  private String username;
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  @Transient
  public Date getRevisionDate() {
      return new Date(timestamp);
  }
  
  public long getTimestamp() {
      return timestamp;
  }
  
  public void setTimestamp(long timestamp) {
      this.timestamp = timestamp;
  }
  
  public String getUsername() {
      return username;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public boolean equals(Object o) {
      if(this == o) return true;
      if(!(o instanceof CustomRevisionEntity)) return false;
  
      CustomRevisionEntity that = (CustomRevisionEntity) o;
  
      if(id != that.id) return false;
      if(timestamp != that.timestamp) return false;
      if(timestamp != that.timestamp) return false;
      if(username != that.username) return false;
  
      return true;
  }
  
  public int hashCode() {
      int result;
      result = id;
      result = 31 * result + (int) (timestamp ^ (timestamp &gt;&gt;&gt; 32));
      return result;
  }
  
  public String toString() {
      return "DefaultRevisionEntity(user = " + username + "id = " + id + ", revisionDate = " + DateFormat.getDateTimeInstance().format(getRevisionDate()) + ")";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And also custom listener:</p>
  
  <pre><code>package com.csbi.samples.audit; 
  import org.hibernate.envers.RevisionListener;
  
  public class CustomRevisionListener implements RevisionListener {
  
  public void newRevision(Object revisionEntity) {
      CustomRevisionEntity revision = (CustomRevisionEntity) revisionEntity;
      revision.setUsername("username"); //for testing
  }
  
  }
  </code></pre>
  
  <p>Here is some lines from log:</p>
  
  <blockquote>
    <p>DEBUG: org.hibernate.envers.configuration.metadata.AuditMetadataGenerator -
    Generating first-pass auditing mapping for entity
    com.csbi.samples.domain.Property.<br>
    DEBUG:
    org.hibernate.envers.configuration.metadata.AuditMetadataGenerator -
    Generating second-pass auditing mapping for entity
    com.csbi.samples.domain.Property.<br>
    INFO : org.hibernate.cfg.HbmBinder
    - Mapping class: com.csbi.samples.domain.Property_AUD -> PROPERTIES_AUD<br>
    INFO : org.hibernate.cfg.HbmBinder - Mapping class:
    org.hibernate.envers.DefaultRevisionEntity -> REVINFO</p>
  </blockquote>
  
  <p>Take a look at the last line of the output.
  There is still <code>DefaultRevisionEntity</code> mapped instead of <code>CustomRevisionEntity</code>.</p>
  
  <p>I have no idea what is wrong. Any suggestions? </p>