-->
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.  [ 2 posts ] 
Author Message
 Post subject: Nhibernate with DTC
PostPosted: Wed Jun 02, 2010 8:03 am 
Newbie

Joined: Wed Jun 02, 2010 7:49 am
Posts: 2
I have a project made using nhibernate and Distributed Transaction Coordinator(MSDTC), I have this "uid=DBA;pwd=sql;DBF={0};AutoStop=No;POOLING=false;start=dbsrv11 -c 32M -tmf -tmt 20" as my connection string, but when i run several tests that have a transaction, it throws the following error:

NHibernate.Exceptions.GenericADOException: could not load an entity: [Plutus.Dominio.Entidades.Agencia#6][SQL: SELECT agencia0_.Id as Id14_0_, agencia0_.Ativo as Ativo14_0_, agencia0_.Nome as Nome14_0_, agencia0_.NumeroAgencia as NumeroAg4_14_0_, agencia0_.NumeroAgenciaDV as NumeroAg5_14_0_, agencia0_.BancoEmpresa_Id as BancoEmp6_14_0_ FROM Agencias agencia0_ WHERE agencia0_.Id=?] ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at iAnywhere.Data.SQLAnywhere.SACommand._ExecuteReader(CommandBehavior commandBehavior, Boolean isExecuteScalar, Boolean isBeginExecuteReader)
at iAnywhere.Data.SQLAnywhere.SACommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister)
--- End of inner exception stack trace ---
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister)
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
at NHibernate.Event.Default.DefaultLoadEventListener.LoadFromDatasource(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options)
at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.Get(String entityName, Object id)
at NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id)
at NHibernate.Impl.SessionImpl.Get[T](Object id)


My transaction is like this:
Code:
using (var transaction = new TransactionScope())
{
        //... save and save
       _session.Flush();
      transaction.Complete();
}


The error happens when run this code:

_session.Get<T>(id);


When I run the same tests without transaction, it doesn't throws any error.

What can I do to fix it?


Top
 Profile  
 
 Post subject: Re: Nhibernate with DTC
PostPosted: Wed Jun 02, 2010 9:30 am 
Newbie

Joined: Wed Jun 02, 2010 7:49 am
Posts: 2
I fix it implementing this class:

Code:
public class ForceEscalationToDistributedTx : IEnlistmentNotification
        {
            private readonly int thread;
            public ForceEscalationToDistributedTx()
            {
                thread = Thread.CurrentThread.ManagedThreadId;
                Transaction.Current.EnlistDurable(Guid.NewGuid(), this, EnlistmentOptions.None);
            }

            public void Prepare(PreparingEnlistment preparingEnlistment)
            {
                Debug.Assert(thread != Thread.CurrentThread.ManagedThreadId);
                preparingEnlistment.Prepared();
            }

            public void Commit(Enlistment enlistment)
            {
                enlistment.Done();
            }

            public void Rollback(Enlistment enlistment)
            {
                enlistment.Done();
            }

            public void InDoubt(Enlistment enlistment)
            {
                enlistment.Done();
            }
        }


And I used it in my transaction:

Code:
using (var transaction = new TransactionScope())
{
       new ForceEscalationToDistributedTx();
        //... save and save
       _session.Flush();
      transaction.Complete();
}


But I have no idea why it works, someone knows what the ForceEscalationToDistributedTx does?
The NHibernate should not do this?


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

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.