0

i would like to better understand the behavior of Hibernate Envers.. Here's the problem : (PostgreSQL) I have this:

Person  (
          id bigint not null, 
          job character varying(10)
)

plus its "_aud" table Person_AUD

Now, i have to do this change:

ALTER TABLE Person
ADD COLUMN group varchar (10);

And, after that, something like this :

UPDATE TABLE Person
SET group='unemployed'
WHERE job=null;

My questions are: what does Hibernate do to my _aud table when i run the "alter table? And, what does Hibernate do to my_aud table when i run the "update"?

I ask this because i can't try it(i have to do this "manually" using Liquibase so I am asking it to you :) )

1 Answers1

0

Working off the assumption that column group is to be audited, you'll need to alter Person_AUD as well just like you did with the Person table:

ALTER TABLE Person_AUD 
ADD COLUMN group varchar(10)

Since the field is NULL-able, it is entirely up to you whether its necessary to also execute a similar update statement on the Person_AUD table. If you want, it would be:

UPDATE Person_AUD 
   SET group = 'unemployed' 
 WHERE job is NULL

It's important to note that the number of rows updated in the Person_AUD table will not necessarily be the same number of updated rows from your Person table, as the audit table may contain multiple rows with differing revisions for the same primary key from Person.

Naros
  • 19,928
  • 3
  • 41
  • 71
  • yes, really thanks for your reply..but i think you missed my real question : "what does Hibernate do to my_aud table when i run the "update"?" For example: I have Person table : ID JOB 0 null After the "alter" and "update" it will be like this : Person : ID JOB GROUP 0 null unemployed How does the Person_AUD table will be? Does it will create a new row including a new REV and adding the REVEND? –  Jun 20 '16 at 09:46
  • Are you using the hbm2ddl configuration setting with `update` ? – Naros Jun 20 '16 at 17:51