Dear all:
When I call session.save. NHibernateException occured.
mapping configuration:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="code_template" assembly="code_template">
<class name="Cat" table="cat">
<id name="Id">
<generator class="NHibernate.Id.Enhanced.SequenceStyleGenerator">
<param name="initial_value">1000</param>
<param name="increment_siz">1</param>
<param name="sequence_name">hibernate_sequence</param>
</generator>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="Name">
<column name="Name" length="16" not-null="true" />
</property>
<property name="Sex" />
<property name="Weight" />
</class>
</hibernate-mapping>
Code:
Configuration cfg = new Configuration();
ISessionFactory sessionFactory = cfg.Configure().BuildSessionFactory();
SchemaExport sExp = new SchemaExport(cfg);
sExp.Create(true, true);
ISession session = sessionFactory.OpenSession();
Cat cat = new Cat();
cat.Name = "dear cat";
session.Save(cat);
session.Close();
sessionFactory.Close();
callstack:
Code:
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>未处理的异常</Description><AppDomain>code_template.vshost.exe</AppDomain><Exception><ExceptionType>NHibernate.HibernateException, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4</ExceptionType><Message>error performing isolated work</Message><StackTrace> 在 NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
在 NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
在 NHibernate.Engine.Transaction.Isolater.DoIsolatedWork(IIsolatedWork work, ISessionImplementor session)
在 NHibernate.Engine.TransactionHelper.DoWorkInNewTransaction(ISessionImplementor session)
在 NHibernate.Id.Enhanced.TableStructure.TableAccessCallback.get_NextValue()
在 NHibernate.Id.Enhanced.OptimizerFactory.NoopOptimizer.Generate(IAccessCallback callback)
在 NHibernate.Id.Enhanced.SequenceStyleGenerator.Generate(ISessionImplementor session, Object obj)
在 NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
在 NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
在 NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
在 NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
在 NHibernate.Impl.SessionImpl.Save(Object obj)
在 code_template.NHibernateOp.test() 位置 D:\code\lts\5-Src\1-Server\code_template\NHibernateOp.cs:行号 28
在 code_template.Program.Main(String[] args) 位置 D:\code\lts\5-Src\1-Server\code_template\Program.cs:行号 28
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()</StackTrace><ExceptionString>NHibernate.HibernateException: error performing isolated work ---&gt; System.InvalidOperationException: Nested transactions are not supported.
在 MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso)
在 MySql.Data.MySqlClient.MySqlConnection.BeginTransaction()
在 MySql.Data.MySqlClient.MySqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)
在 System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction()
在 NHibernate.Id.Enhanced.TableStructure.DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn, IDbTransaction transaction)
在 NHibernate.Engine.TransactionHelper.Work.DoWork(IDbConnection connection, IDbTransaction transaction)
在 NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
--- 内部异常堆栈跟踪的结尾 ---
在 NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
在 NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)
在 NHibernate.Engine.Transaction.Isolater.DoIsolatedWork(IIsolatedWork work, ISessionImplementor session)
在 NHibernate.Engine.TransactionHelper.DoWorkInNewTransaction(ISessionImplementor session)
在 NHibernate.Id.Enhanced.TableStructure.TableAccessCallback.get_NextValue()
在 NHibernate.Id.Enhanced.OptimizerFactory.NoopOptimizer.Generate(IAccessCallback callback)
在 NHibernate.Id.Enhanced.SequenceStyleGenerator.Generate(ISessionImplementor session, Object obj)
在 NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
在 NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
在 NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
在 NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
在 NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
在 NHibernate.Impl.SessionImpl.Save(Object obj)
在 code_template.NHibernateOp.test() 位置 D:\code\lts\5-Src\1-Server\code_template\NHibernateOp.cs:行号 28
在 code_template.Program.Main(String[] args) 位置 D:\code\lts\5-Src\1-Server\code_template\Program.cs:行号 28
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()</ExceptionString><InnerException><ExceptionType>System.InvalidOperationException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Nested transactions are not supported.</Message><StackTrace> 在 MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso)
在 MySql.Data.MySqlClient.MySqlConnection.BeginTransaction()
在 MySql.Data.MySqlClient.MySqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)
在 System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction()
在 NHibernate.Id.Enhanced.TableStructure.DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn, IDbTransaction transaction)
在 NHibernate.Engine.TransactionHelper.Work.DoWork(IDbConnection connection, IDbTransaction transaction)
在 NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)</StackTrace><ExceptionString>System.InvalidOperationException: Nested transactions are not supported.
在 MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso)
在 MySql.Data.MySqlClient.MySqlConnection.BeginTransaction()
在 MySql.Data.MySqlClient.MySqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)
在 System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction()
在 NHibernate.Id.Enhanced.TableStructure.DoWorkInCurrentTransaction(ISessionImplementor session, IDbConnection conn, IDbTransaction transaction)
在 NHibernate.Engine.TransactionHelper.Work.DoWork(IDbConnection connection, IDbTransaction transaction)
在 NHibernate.Transaction.AdoNetTransactionFactory.ExecuteWorkInIsolation(ISessionImplementor session, IIsolatedWork work, Boolean transacted)</ExceptionString></InnerException></Exception></TraceRecord>
Thanks for all for help