-
1. Re: ValidityAuditStrategy with no audit record
azagorneanu Dec 18, 2010 6:23 AM (in response to 0x3333)I was having the same issue. Seems that ValidityAuditStrategy tries always to update the REVEND of previous version, even if the audit table is empty. This is causing problems when you are migrating to ValidityAuditStrategy or when you start using Envers with entities which already exists (then the update for these entities will fail).
-
2. Re: ValidityAuditStrategy with no audit record
0x3333 Dec 20, 2010 9:15 AM (in response to azagorneanu)I made it work just removing the else that thrown that exception. everything is working now. I will fill a bug when JIRA get up again.
174,177c174 < } else { < throw new RuntimeException("Cannot find previous revision for entity " + auditedEntityName + " and id " + id); < } --- > }
-
3. Re: ValidityAuditStrategy with no audit record
fbascheper Dec 20, 2010 9:38 AM (in response to 0x3333)Hi,
There should always be exactly one row in the audit table where revend is null for any id referring to the auditedTable (except for the auditjoinTable where the situation is slightly more complicated: there should be one row with revend null for a joincolumn / inversejoincolumn combination).
Which implies that the exception thrown in this code should be correct. However, there's probably something else going wrong.
I have seen some situations where the o.h.e.entities.mapper.relation.AbstractCollectionMapper did not create new AuditJoinTable rows. This was caused by invalid equals() and hashCode() methods.
Maybe you're seeing something similar. I'd be very interested in any testcase you can provide for this exception.
-
4. Re: ValidityAuditStrategy with no audit record
0x3333 Dec 20, 2010 9:43 AM (in response to fbascheper)Erik,
I see, but sometimes a table is filled outside, from a external program for example, in that case we don't have a row in the audit table.
-
5. Re: ValidityAuditStrategy with no audit record
fbascheper Dec 20, 2010 10:34 AM (in response to 0x3333)Yes that would cause problems. External modifications to the database should create audit rows as well.
-
6. Re: ValidityAuditStrategy with no audit record
adamw Dec 22, 2010 3:29 PM (in response to 0x3333)Just as Erik said, if a row is added outside of Hibernate/Envers, you have to manually initialize the audit table with an initial revision, type = 0 (ADD).
Adam
-
7. ValidityAuditStrategy with no audit record
0x3333 Feb 24, 2011 10:03 AM (in response to 0x3333)FYI, I'm working on a code that will create the records in the audit table if there is none.
Tercio
-
8. Re: ValidityAuditStrategy with no audit record
vincenzo.vitale Mar 10, 2011 8:29 AM (in response to adamw)Why not letting envers working fine whitout trhowing the exception in the case the audit table for that element is not initialized?
-
9. Re: ValidityAuditStrategy with no audit record
adamw Mar 11, 2011 1:53 AM (in response to vincenzo.vitale)Because it shouldn't happen in normal situations - the only exception is non-migrated data.
Adam
-
10. Re: ValidityAuditStrategy with no audit record
dserodio Mar 11, 2013 1:39 PM (in response to 0x3333)Tercio Ferdinando Gaudencio Filho wrote:
FYI, I'm working on a code that will create the records in the audit table if there is none.
Tercio
I need something similar to what you described: I'm enabling Envers in an existing database, so the tables are full of data but the audit tables are empty. Did you find a solution for this?
-
11. Re: ValidityAuditStrategy with no audit record
0x3333 Mar 13, 2013 5:06 PM (in response to dserodio)Hi!
Unfortunatelly, I don't have a solution yet.
I was working in a solution directly in the database. Because if the database is big enough, creating the objects in memory would take forever.
I did some work in MySQL creating some SPs but until now I don't have a working solution for this.
If you can, we could work together in a solution for this. I think that it woud be helpfull for a lot devs out there.
Tercio
-
12. Re: ValidityAuditStrategy with no audit record
dserodio Mar 26, 2013 2:34 PM (in response to 0x3333)I'm using PostgreSQL, so a solution for MySQL databases wouldn't help me much. From what I've researched, it seems the best place to implement this solution would be
AuditEventListener
. On update or delete, check if the audit table already contains the history (ie the "ADD" record) for this entity. If if doesn't, insert the "ADD" record, and then the "MOD" record.This way no database space would be wasted for entities that were never modified or deleted, and no manual INSERT of records would be needed.
My doubt is what do about the revision number, because they are "global" and not specific to the modified entity. What do you think?
-
13. Re: ValidityAuditStrategy with no audit record
adamw Mar 26, 2013 2:45 AM (in response to dserodio)Well, but that would require an additional query on each write, wouldn't it slow things down>
The revision number would have to be the same as for the MOD, I guess.
Adam
-
14. Re: ValidityAuditStrategy with no audit record
dserodio Mar 26, 2013 2:47 PM (in response to adamw)This specific application where I need to enable auditing receives few UPDATEs, and the database is a very powerful (and under-utilized) machine so I don't think performance would be a problem. Besides the possible performance issue, do you think this approach would work?