Issue setting up Custom Revision Entity
code6226 Jul 20, 2010 9:09 AMI 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:
@Entity @RevisionEntity(MyHistoryRevisionListener.class) 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"/> </id> <property name="timestamp" column="REVTSTMP" /> <property name="username" column="LOGIN_NAME" length="255"/> </class> </hibernate-mapping>
Here's the listener:
public class MyHistoryRevisionListener implements RevisionListener { public void newRevision(Object revisionEntity) { MyHistoryRevisionEntity exampleRevEntity = (MyHistoryRevisionEntity) revisionEntity; exampleRevEntity.setUsername("Bob"); } }
Any ideas?