A have set Envers in my Spring Boot project. Now I need to insert some data to my tables and I want to do it in Flyway migration script. But I have to ensure that these data will also be inserted to audit tables. Otherwise I can get errors like
javax.persistence.EntityNotFoundException: Unable to find XYZ with id 1
when browsing history with
Do I need to insert data to audit tables (and also to REVINFO table) manually in the migration script or is there any other option, which would engage Hibernate Envers to do it for me?
My solution to this very issue has been to use the Hibernate Maven Plugin to help me generate an example
create.sql from my JPA entities, and use that as guidance for my Flyway migrations.
But, yes, I ended up having to add the REVINFO table in the first migration when I added envers, and adding the _AUD tables as I’m adding new audited entiites.
Well, for initial DB schema setup I did it similarly like you described. No problem. All audit tables and revinfo table are in place. Database is populated.
But now I need to add some more data manually (INSERT), like a new timezone record in timezones table. And I would like to avoid updating audit tables and REVINFO table manually…
Sorry, I haven’t had to solve that particular problem yet. I’d wonder if a Java-based migration would help? You’d probably have to do some lower level calls to JPA/Hibernate instead of the sort of direct JDBC stuff they show in the documentation, though. (You may even be able to make that a repeatable migration, and have it driven by
Yes, I was thinking about the java-based migration too. However you only have JDBC (or business objects if you are using Spring) there. I wonder if it would be possible to use Hibernate then, which would do the audit part of the job.