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
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With