There is no previous one. It is the “current” one. Data was imported with SQL loading and before we had Envers working.
So now, if I change something, the new version is saved in the audit-tables. But I have no way to find out the version before.
There is the need, definitely. And I am not the only one. But I did not find a nice solution for now.
We are using MySQL, what I came up with now, is, for each audited table (we save the user which changed the data, too, so we have a revinfo table):
set @i=(select max(id) from revinfo);
insert into table_aud (id, rev, revtype, ...all other columns)
select id,
@i + (ROW_NUMBER() over (ORDER BY id)) as rev,
0 as revtype,
...all other columns
from table;
insert into revinfo
select rev, NOW() as timestamp, 'user' as username from table_aud
where rev > @i;
Not very nice, and it has to be done for any audited table, but works.
I had to increase the value in table hibernate_sequence, too.
update hibernate_sequence set next_val = (select max(id)+1 from revinfo);