Hibernate Envers - REVINFO table does not exist

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

When I run my code that works fine, retaining @Audited without annotation, I get org.hibernate.exception.SQLGrammarException:

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

I do not see any documentation about creating the REVINFO table, so I assume that it will be created automatically, but this does not seem to happen. Did I miss something?

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

Thanks Reuven

+6
source share
2 answers

Yes, see below: chapter 7. For each entity, you need a REV INFO table and a default audit table named {entity name} _AUD, although this is customizable. In order for them to be generated automatically, you will need to enable the creation of the Hibernate schema.

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

I usually start the generation of the schema against the test database, and then synchronize the changes with the application database using some DB tool.

See also details about the Ant task, which you can use to generate DDL:

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

+6
source

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

I also had the same problem and I just solved it by adding the property above.

Thanks.

+1
source

Source: https://habr.com/ru/post/976311/


All Articles