0
我正在使用Castle Active Record和NHibernate,並且需要能夠在不使用會話的情況下運行HQL更新。當我使用會話時,它最終導致鎖定問題:在AR和Nhibernate中運行沒有會話的hql更新
public static ISession GetSession(out ISessionFactoryHolder factoryHolder, out bool created)
{
created = false;
var type = typeof(T);
factoryHolder = ActiveRecordMediator.GetSessionFactoryHolder();
ISessionScope activeScope = factoryHolder.ThreadScopeInfo.GetRegisteredScope();
ISession session = null;
var key = factoryHolder.GetSessionFactory(type);
if (activeScope == null)
{
created = true;
session = factoryHolder.CreateSession(type);
}
else
{
if (activeScope.IsKeyKnown(key))
session = activeScope.GetSession(key);
else
session = factoryHolder.GetSessionFactory(type).OpenSession();
}
return session;
}
public static void UpdateQuery(string query)
{
ISessionFactoryHolder factoryHolder;
var created = false;
var session = GetSession(out factoryHolder, out created);
session.CreateQuery(query).ExecuteUpdate();
if (created)
factoryHolder.ReleaseSession(session);
}
由於會話中發生的所有鎖都在我們的生產環境中造成重大問題。我如何在不實例化會話的情況下運行hql更新?