From 53626310cf27cd3507909af759d93dd55dd3f6fd Mon Sep 17 00:00:00 2001 From: Adam Warski Date: Mon, 12 Sep 2011 09:01:33 +0200 Subject: [PATCH] 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 --- .../hibernate/envers/strategy/ValidityAuditStrategy.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java index b9a9cdadb0..c2edc22b4e 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/strategy/ValidityAuditStrategy.java @@ -3,6 +3,8 @@ import java.io.Serializable; import java.util.Date; import java.util.List; import java.util.Map; + +import org.hibernate.LockOptions; import org.hibernate.Session; import org.hibernate.envers.RevisionType; import org.hibernate.envers.configuration.AuditConfiguration; @@ -71,7 +73,7 @@ public class ValidityAuditStrategy implements AuditStrategy { addEndRevisionNullRestriction(auditCfg, qb); @SuppressWarnings({"unchecked"}) - List l = qb.toQuery(session).list(); + List l = qb.toQuery(session).setLockOptions(LockOptions.UPGRADE).list(); updateLastRevision(session, auditCfg, l, id, auditedEntityName, revision); } @@ -100,7 +102,7 @@ public class ValidityAuditStrategy implements AuditStrategy { addEndRevisionNullRestriction(auditCfg, qb); - final List l = qb.toQuery(session).list(); + final List l = qb.toQuery(session).setLockOptions(LockOptions.UPGRADE).list(); // 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