Description When hibernate orm is used under load, and data that is beeing administrated is not separated per session ( let's say we have one entity that is to be referenced by multiple users ), corruption of audited data occurs, and using AuditReader to obtain entity in some revision is impossible due to NonUniqueResultException ( there are two entities at some revision). Steps to reproduce This bug is not easly reproducible, and there will be no test cause it would consume to much time to create, but there is nice image describing the issue http://tenmilesquare.com/build-a-stateful-system-with-envers/ , under the section "The Race Condition". But there is an option to create this issue using debugger and a breakpoint. First there has to be set ValidityAuditStrategy with revision_on_collection_change as true. 1. Create self referencing entity with bidirectional OneToMany relationship. 1a. Create breakpoints in AuditProcess on method public Object getCurrentRevisionData(Session session, boolean persist). 2. In separate sessions start assignment of entity A to both entity B and entity C. 3. The threads should lock on breakpoints, let the first thread generate revision 4. then let the second thread to generate revision and then persist it 5. let the first thread to save the audits. The result is that two rows are generated, but the rev and revend overlap (screenshot). Attaching the microproject for wildfly 8.2.1 , but the bug is reproducible on every server. |