如果您查看AdoTransaction
(ref)中的以下代码,您将看到NH在尝试提交时如何对错误做出反应。
if (session.FlushMode != FlushMode.Manual)
{
session.Flush();
}
NotifyLocalSynchsBeforeTransactionCompletion();
session.BeforeTransactionCompletion(this);
try
{
trans.Commit();
log.Debug("DbTransaction Committed");
committed = true;
AfterTransactionCompletion(true);
Dispose();
}
catch (HibernateException e)
{
log.Error("Commit failed", e);
AfterTransactionCompletion(false);
commitFailed = true;
// Don't wrap HibernateExceptions
throw;
}
catch (Exception e)
{
log.Error("Commit failed", e);
AfterTransactionCompletion(false);
commitFailed = true;
throw new TransactionException("Commit failed with SQL exception", e);
}
finally
{
CloseIfRequired();
}
虽然事务没有显式回滚,但它当然没有提交。因此,我认为你的问题的答案是肯定的,等待数据库更改将被回滚。
有意思的是,Flush()
的电话没有包含在try
中。因此,值得注意的是,这里捕获的异常可能会使Session
处于不可预知的状态。因此,guidance处理异常。
请仔细阅读上面的链接,确保您正确地处理交易,如果可能,请使用“使用”声明。 –