问题
In the application which I am working on I use spring, hibernate and envers for auditing. envers works with calls like, hibernateTemplate.insert, hibernateTemplate.save, hibernateTemplate.saveOrUpdate. But it doesnt seem to work when i call hibernateTemplate.bulkUpdate.
I googled for solutions and found that envers doesnt support bulkUpdate.
A work around has been provided in the link below but i am not able to get it.
Envers Bulk insert/updates
It would be of help if someone can provide a workaround/sample for this.
Thanks
回答1:
The documentation is correct. HQL and native SQL operations are not audited.
Since the performance of the bulk update will be affected by auditing, you may wish to change your design - for example, if you have a parent entity with related children, and you are performing a bulk update on the child records, you could update attributes of the parent record and then call saveOrUpdate after doing the bulk update.
Another option, is to manually perform the bulk update on the audit table(s) also, but its not going to be elegant. I managed to get around the issue in my case by changing the design as per the above.
来源:https://stackoverflow.com/questions/12370596/work-around-for-envers-auditing-for-bulk-update