미리 채워진 숫자의 열로 구성된 표가 있습니다. Nhibernate를 사용하는 API는 'Used'플래그가 false로 설정된 처음 10 개의 행을 가져옵니다. 여러 세션이 테이블에서 행을 가져 오려고 할 때 동시성 문제를 피할 수있는 최선의 방법은 무엇입니까? 행을 선택한 후 플래그 열을 True로 업데이트하여 후속 호출이 동일한 번호를 사용하지 않도록 할 수 있습니다.Nhibernate 여러 세션 간의 동시성
// RepeatableRead ensures the read rows does not get concurrently updated by another
// session.
using (var tran = session.BeginTransaction(IsolationLevel.RepeatableRead))
{
var entities = session.Query<Entity>()
.Where(e => !e.Used)
.OrderBy(e => e.Id)
.Take(10)
.ToList();
foreach(var entity in entities)
{
e.Used = true;
}
// If your session flush mode is not the default one and does not cause
// commits to flush the session, add a session.Flush(); call before committing.
tran.Commit();
return entities;
}
그것은 간단하다 : 이러한 일반적인 문맥으로
이렇게하려면 여러 가지 방법이 있습니다. 그 이유는 질문이 의견을 기반으로하기 때문입니다. 또한, 질문은 NHibernate와는 거의 관계가 없다. –