-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Nhibernate with mysql : error performing isolated work
PostPosted: Tue Oct 25, 2011 3:09 am 
Newbie

Joined: Wed Nov 02, 2005 5:30 am
Posts: 2
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 ---&amp;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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.