1 Reply Latest reply on Feb 18, 2016 10:44 AM by Daniel Brumusescu


    Tomaž Majerhold Newbie

      'm using Hibernate-Core:4.3.11.Final and Hibernate-Envers:4.3.11.Final and I have my implementation of org.hibernate.envers.RevisionListener

      and I have my revision entity(MyRevisionEntity) which extend org.hibernate.envers.DefaultRevisionEntity but envers still using default org.hibernate.envers.DefaultRevisionEntity.

      public class MyRevisionListener implements RevisionListener {
          public void newRevision(Object o) {
              MyRevisionEntity myRev = (MyRevisionEntity) o;


      @Table(name = "my_revision")
      public class MyRevisionEntity extends DefaultRevisionEntity {


      What I'm doing wrong?

      Then on documentation I find:

      If your RevisionListener class is inaccessible from @RevisionEntity (e.g. exists in a different module), set org.hibernate.envers.revision_listener property to it's fully qualified name. Class name defined by the configuration parameter overrides revision entity's value attribute.


      so I add:

      org.hibernate.envers.revision_listener: db.MyRevisionListener


      but then I get error:

      ERROR [2015-12-23 12:16:27,157] org.hibernate.AssertionFailure: HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session):
      ! java.lang.ClassCastException: org.hibernate.envers.DefaultRevisionEntity cannot be cast to db.MyRevisionEntity
      ! at arnes.dropwizard.db.ArisRevisionListener.newRevision(ArisRevisionListener.java:21) ~[classes/:na]
      ! at org.hibernate.envers.internal.revisioninfo.DefaultRevisionInfoGenerator.generate(DefaultRevisionInfoGenerator.java:107) ~[hibernate-envers-4.3.11.Final.jar:4.3.11.Final]
      ! at org.hibernate.envers.internal.synchronization.AuditProcess.getCurrentRevisionData(AuditProcess.java:127) ~[hibernate-envers-4.3.11.Final.jar:4.3.11.Final]
      ! at org.hibernate.envers.internal.synchronization.AuditProcess.executeInSession(AuditProcess.java:109) ~[hibernate-envers-4.3.11.Final.jar:4.3.11.Final]
      ! at org.hibernate.envers.internal.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:161) ~[hibernate-envers-4.3.11.Final.jar:4.3.11.Final]
      ! at org.hibernate.envers.internal.synchronization.AuditProcessManager$1.doBeforeTransactionCompletion(AuditProcessManager.java:63) ~[hibernate-envers-4.3.11.Final.jar:4.3.11.Final]
      ! at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:722) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]

      It is very strange because MyRevisionEntity extend DefaultRevisionEntity .


      Any idea?


      Regards, Tomaz

        • 1. Re: RevisionEntity
          Daniel Brumusescu Newbie

          Dear @


          I also had an issue while extending the class DefaultRevisionEntity.

          It did not recognize the fact that the superclass already has an @Id.

          I used hibernate-envers-4.2.0.Final-redhat-1.


          Try the following - in my case it worked:

          No longer extend DefaultRevisionEntity, but instead just implement yourself all the required fields/methods of @RevisionEntity (meaning @RevisionNumber and @RevisionTimestamp) - you can just look in the source code of DefaultRevisionEntity and copy paste it into your own MyRevisionEntity class).


          An example below: (userName is an extra field that you can add - just add as many extra fields you want to the MyRevisionEntity class - to be stored in the MyRevisionEntity entity)


          public class MyRevisionEntity /* extends DefaultRevisionEntity */ implements Serializable {
              private static final long serialVersionUID = -4652932137150123490L;
              private String userName;
              private int id;
              private long timestamp;
              public int getId() {
                  return id;
              public void setId(int id) {
                  this.id = id;
              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 int hashCode() {
                  final int prime = 31;
                  int result = 1;
                  result = prime * result + id;
                  result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
                  result = prime * result + ((userName == null) ? 0 : userName.hashCode());
                  return result;
              public boolean equals(Object obj) {
                  if (this == obj)
                      return true;
                  if (obj == null)
                      return false;
                  if (getClass() != obj.getClass())
                      return false;
                  UserRevision other = (UserRevision) obj;
                  if (id != other.id)
                      return false;
                  if (timestamp != other.timestamp)
                      return false;
                  if (userName == null) {
                      if (other.userName != null)
                          return false;
                  } else if (!userName.equals(other.userName))
                      return false;
                  return true;