-
1. Re: Audit records for entities that weren't actually modified
adamw Nov 21, 2010 1:38 PM (in response to appletree)This can be if you have an entity with a many-to-one or many-to-many relations. A revision is generated if an entity is added or removed from the collection. This is not reflected as a change to a DB field, but a field in the entity is somehow changed, hence the revision. You can turn this off by setting the
org.hibernate.envers.revision_on_collection_change configuration option. See the manual for more details.
Adam
-
2. Re: Audit records for entities that weren't actually modified
appletree Nov 23, 2010 1:23 AM (in response to adamw)That setting didn't help. We aren't modifying any relationships, nothing's being modified... well things are being hibernate updated, but there are no actual changes. There's a bug somewhere, probably in our code. But I would hope that envers wouldn't have allowed this to happen. I'll report back once I've thoroughly debugged the situation.
-
3. Re: Audit records for entities that weren't actually modified
adamw Nov 23, 2010 6:53 AM (in response to appletree)Hmm that's interesting. Let me know if you find out anything, I'm curious what's happening too
Adam
-
4. Re: Audit records for entities that weren't actually modified
rsvato Nov 24, 2010 7:26 PM (in response to adamw)Hello Adam,
Event with this setting new revision is created for the object if any of its persistent collections changed. I prepared a small test case for it here: https://github.com/rsvato/audit-cascade-demo
Book has many authors. If you create author and set a book for him, no revision for book is created, but if you add new author to the authors collection, new book revision is created with new author. Is it expected behavior?
-
5. Re: Audit records for entities that weren't actually modified
appletree Nov 24, 2010 8:13 PM (in response to rsvato)So yes it makes no sense that a new Book revision is created in Sviatoslav's example. There's also a more insidious problem in our case, and I assume in the Book/Authors testcase above, in that any one-to-one or one-to-many entities in Book will also get unnecessary revisions when none of them have changed.
-
6. Re: Audit records for entities that weren't actually modified
florin13 Nov 25, 2010 5:09 PM (in response to appletree)Hi guys,
I've looked in the Book/Author testcase. A bidirectional one-to-many relationship with the "one" end set as the owner is correct from the hibernate annotations point of view. This is an excerpt taken from the hibernate annotation documentation regarding this kind of relationship:
Could these additional update statements be the reason envers creates the non-sensical revisions?
-
7. Re: Audit records for entities that weren't actually modified
rsvato Nov 25, 2010 5:11 PM (in response to florin13)Additional update statements occur when you use this insertable="false",updatable="false". In this case Hibernate insert record, and after it updates it. But it's not the case of example. Moreover, how I'm understanding, Envers relies on session state rather than on database updates.
-
8. Re: Audit records for entities that weren't actually modified
adamw Nov 30, 2010 4:09 PM (in response to rsvato)Well with the default setting (org.hibernate.envers.revision_on_collection_change = true) I think a new Book revision should be created both when a new Author is created an when an author is changed. With org.hibernate.envers.revision_on_collection_change = false there should be no Book revisions.
Maybe you could create a JIRA for that, and convert your test to an Envers testcase?
Adam
-
9. Re: Audit records for entities that weren't actually modified
rsvato Nov 30, 2010 6:07 PM (in response to adamw)Thanks for answer.
I created a JIRA issue some time ago. It's http://opensource.atlassian.com/projects/hibernate/browse/HHH-5756. If you'd like, I'll convert test to a Envers testcase.
-
10. Re: Audit records for entities that weren't actually modified
adamw Dec 1, 2010 1:05 PM (in response to rsvato)Ah great, thanks. A test case is always very helpful. If you've got the time, maybe you'd want to attempt to fix the issue - just clone the github repo and send a pull request later
Adam
-
11. Re: Audit records for entities that weren't actually modified
rsvato Dec 1, 2010 7:40 PM (in response to adamw)Fixed for branch 3.6. Could you please look at it before pull request?
This is commit link: https://github.com/rsvato/hibernate-core/commit/3091bbda15b24a0bdf330f4f48b2772616b70583
Problem is that onCollectionAction() method of AuditEventListener class completely ignores setting org.hibernate.envers.revision_on_collection_change