2 Replies Latest reply on Jul 21, 2010 6:37 AM by Robin G

    Issue setting up Custom Revision Entity

    Robin G Newbie

      I tried to follow the manual closely, as I also just want to add a username. We use Spring and Hibernate Mapping files.


      Ant properly generates the new database Revision Entity table, and not the old one (REVINFO) anymore, but when it's time to actually add revisions (which I had working previously with the default REVINFO table), the following error is thrown:


      [java] org.springframework.dao.InvalidDataAccessResourceUsageException: could not insert: [org.hibernate.envers.DefaultRevisionEntity]; SQL [insert into REVINFO (REVTSTMP) values (?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not insert: [org.hibernate.envers.DefaultRevisionEntity]
           [java]     at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)


      So it seems like Envers is still trying to use the DefaultRevisionEntity and the default REVINFO table rather than my constum Entity class with its differently named table REV_ENTITY (See HBM below).


      Here's my custom revision entity, MyHistoryRevisionEntity:

      public class MyHistoryRevisionEntity extends DefaultRevisionEntity {
        private String username;
        public String getUsername() {
          return username;
        public void setUsername(String username) {
          this.username = username;


      I use an HBM, so I don't think the @Entity annotation does anything, but leaving it off didn't change anything either.


      This is my Hibernate Mapping for MyHistoryRevisionEntity:

      <hibernate-mapping package="my.software.persistence.history">
          <class name="MyHistoryRevisionEntity" table="REV_ENTITY">
          <id name="id" column="REV" >
               <generator class="increment"/>
          <property name="timestamp" column="REVTSTMP" />
          <property name="username" column="LOGIN_NAME" length="255"/>


      Here's the listener:

      public class MyHistoryRevisionListener implements RevisionListener {
        public void newRevision(Object revisionEntity) {
          MyHistoryRevisionEntity exampleRevEntity = (MyHistoryRevisionEntity) revisionEntity;


      Any ideas?

        • 1. Re: Issue setting up Custom Revision Entity
          Hernán Chanfreau Master



          The revision entity must be a hibernate persistent entity. So... if you are using hbm mappings, the defaultRevEnty mapping defined by envers could be missing. Besides, you can´t mix annotations mappings and xml mappings on the same hierarchy, so try writting your own rev entity without extending the default one and mapping all properties on your xml file.


          Hope it will help.



          1 of 1 people found this helpful
          • 2. Re: Issue setting up Custom Revision Entity
            Robin G Newbie

            Thanks for the tip.


            Turns out that that I incorrectly linked to the HBM mapping from Spring. I did properly link to it from the hibernate config xml, but Spring insists on its own config via applicationContext.xml, which is where my mistake was.


            So now it works with the code above in tact. Yay!