HHH-6647: requesting an upgraded lock when looking for the last audit record to make sure the same one isn't found by two concurrent transactions

This commit is contained in:
Adam Warski 2011-09-12 09:01:33 +02:00
parent 6df15ef85a
commit 53626310cf

View File

@ -3,6 +3,8 @@
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.hibernate.LockOptions;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.envers.RevisionType; import org.hibernate.envers.RevisionType;
import org.hibernate.envers.configuration.AuditConfiguration; import org.hibernate.envers.configuration.AuditConfiguration;
@ -71,7 +73,7 @@ public void perform(Session session, String entityName, AuditConfiguration audit
addEndRevisionNullRestriction(auditCfg, qb); addEndRevisionNullRestriction(auditCfg, qb);
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
List<Object> l = qb.toQuery(session).list(); List<Object> l = qb.toQuery(session).setLockOptions(LockOptions.UPGRADE).list();
updateLastRevision(session, auditCfg, l, id, auditedEntityName, revision); updateLastRevision(session, auditCfg, l, id, auditedEntityName, revision);
} }
@ -100,7 +102,7 @@ public void performCollectionChange(Session session, AuditConfiguration auditCfg
addEndRevisionNullRestriction(auditCfg, qb); addEndRevisionNullRestriction(auditCfg, qb);
final List<Object> l = qb.toQuery(session).list(); final List<Object> l = qb.toQuery(session).setLockOptions(LockOptions.UPGRADE).list();
// Update the last revision if one exists. // Update the last revision if one exists.
// HHH-5967: with collections, the same element can be added and removed multiple times. So even if it's an // HHH-5967: with collections, the same element can be added and removed multiple times. So even if it's an