Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate envers revision tables with existing data from Hibernate Entities

Tags:

I'm adding envers to an existing hibernate entities. Everything is working smoothly so far as far as auditing, however querying is a different issue because the revision tables aren’t populated with the existing data. Has anyone else already solved this issue? Maybe you’ve found some way to populate the revision tables with the existing table? Just thought I’d ask, I'm sure others would find it useful.

like image 945
danieljimenez Avatar asked May 22 '09 15:05

danieljimenez


1 Answers

We populated the initial data by running a series of raw SQL queries to simulate "inserting" all the existing entities as if they had just been created at the same time. For example:

insert into REVINFO(REV,REVTSTMP) values (1,1322687394907);  -- this is the initial revision, with an arbitrary timestamp  insert into item_AUD(REV,REVTYPE,id,col1,col1) select 1,0,id,col1,col2 from item;  -- this copies the relevant row data from the entity table to the audit table 

Note that the REVTYPE value is 0 to indicate an insert (as opposed to a modification).

like image 66
deryl Avatar answered Sep 24 '22 21:09

deryl