-
1. Re: Comparing audited record date with manually set date
adamw Feb 24, 2012 2:27 PM (in response to ijabz)I don't quite get it, why "... when I actually do a save the date set set by Envers is always going to be later than the lastModifiedDate I set ..."? If you need some special fields, maybe look at revision entities?
Adam
-
2. Re: Comparing audited record date with manually set date
ijabz Feb 24, 2012 3:22 PM (in response to adamw)Because if I set timestamp to x ,and then persist the entity the audited record timestamp is going to be x + delta, where delta is the time it takes to save the entity.
One idea I had was to to not audit the last save, whereby I just save the timestamp and no other data, but I don't know if it is possible to selectively audit records
-
3. Re: Comparing audited record date with manually set date
adamw Feb 25, 2012 7:15 AM (in response to ijabz)I'd just add your timestamp to a custom revision entity.
Adam
-
4. Re: Comparing audited record date with manually set date
ijabz Feb 29, 2012 4:52 AM (in response to adamw)I thought I has a simpler solution I added @NotAudited to lastModifiedDate
However if I retrieve the entity from the database and just modify the lastModifiedDate field and nothing else Envers still write a new audit record, the audit table doesnt contain the lastModifiedDate field but it still creates a revision, why ?
I thought Envers was intelligent enough to realise when nothing of relevance had changed, in fact in a test case Id written I called a set method on a field but just set it to the its existing value and this didnt trigger an audit record to be created which is why I thought this.
-
5. Re: Comparing audited record date with manually set date
adamw Feb 29, 2012 11:45 AM (in response to ijabz)It should be - that is it should only write changes if a field changed.
Please breakpoint in EnversPostUpdateEventListenerImpl to see what's changed (ModWorkUnit.changes holds the changes).
Adam
-
6. Re: Comparing audited record date with manually set date
ijabz Mar 7, 2012 10:37 AM (in response to adamw)Hi, found the problem.
I retrieved my entity, but the method that retrieved the entity created and then closed a session, so although I had created a session and started a transaction in the calling method the entity was transient even though session.update() worked for me I think that this must have confused Envers. When I passed the session to from the calling method into the entity retrieval message the update of the lastModifiedDate no longers triggers Envers to create the unneccessary audit record.