Hibernate Envers - REVINFO table doesn't exist

rweiser picture rweiser · Oct 6, 2014 · Viewed 11.5k times · Source

I'm using Hibernate 4.3.6, and I tried making use of the Envers functionality by adding the @Audited annotation to one of my @Entity classes. (The envers jar - hibernate-envers-4.3.6.Final.jar - is on my CLASSPATH.)

When I run my code, which works fine persisting without the @Audited annotation, I get an org.hibernate.exception.SQLGrammarException:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'dbname.REVINFO' doesn't exist

I don't see any documentation about having to create the REVINFO table, so I'd assume it would be created automatically, but that doesn't seem to be happening. Am I missing something?

(If I create it manually, as per the schema described here - http://thinkinginsoftware.blogspot.co.il/2011/03/auditing-entities-with-hibernate-jpa.html - then I get an exception that *_AUD doesn't exist. I guess I have the same question about all the *_AUD tables.)

Thanks, Reuven

Answer

Alan Hay picture Alan Hay · Oct 6, 2014

Yes, see the below: chapter 7. You need the REV INFO table and an audit table per entity, by default named {entity name}_AUD although this is configurable. To have them generated automatically you would need to enable Hibernate schema generation.

http://docs.jboss.org/envers/docs/

I normally run schema generation against a test database and then synch the changes over to application database using some DB tool.

See also here for details of an Ant task which you can use to generate the DDL:

http://docs.jboss.org/hibernate/core/4.1/devguide/en-US/html/ch15.html#envers-generateschema