Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Envers - REVINFO table doesn't exist

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

like image 332
rweiser Avatar asked Oct 06 '14 17:10

rweiser


2 Answers

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

like image 148
Alan Hay Avatar answered Oct 06 '22 15:10

Alan Hay


Please re check you have added <prop key="hibernate.hbm2ddl.auto">update</prop>property in the spring configuration file.

I also had same issue and just resolved it by adding above property.

Thanks.

like image 3
Vish Avatar answered Oct 06 '22 14:10

Vish