Samir
unread,Feb 19, 2011, 7:33:37 AM2/19/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nhusers
We are having an application which is working file in development
environment, but in the test environment, we get an exception whenever
we try to perform second operation within a transaction scope.
Pseudocode that is causing the issue:
using (TransactionScope tScope = new TransactionScope())
{
using (ISession session = sessionFactory.OpenSession())
{
session.SaveOrUpdate(obj1); // some transient obj
session.Flush();
}
using (ISession session = sessionFactory.OpenSession())
{
session.SaveOrUpdate(obj2); // some another transient obj
session.Flush(); // Exception occurs here
}
}
The exception that occurs:
Message: Error has occured in service:
System.Transactions.TransactionException: The operation is not valid
for the state of the transaction.
at
System.Transactions.TransactionState.EnlistVolatile(InternalTransaction
tx, IEnlistmentNotification enlistmentNotification, EnlistmentOptions
enlistmentOptions, Transaction atomicTransaction)
at
System.Transactions.Transaction.EnlistVolatile(IEnlistmentNotification
enlistmentNotification, EnlistmentOptions enlistmentOptions)
at
NHibernate.Transaction.AdoNetWithDistributedTransactionFactory.EnlistInDistributedTransactionIfNeeded(ISessionImplementor
session)
at
NHibernate.Impl.AbstractSessionImpl.EnlistInAmbientTransactionIfNeeded()
at
NHibernate.Impl.AbstractSessionImpl.CheckAndUpdateSessionStatus()
at NHibernate.Impl.SessionImpl.get_Batcher()
at NHibernate.Type.DbTimestampType.UsePreparedStatement(String
timestampSelectString, ISessionImplementor session)
at
NHibernate.Type.DbTimestampType.GetCurrentTimestamp(ISessionImplementor
session)
at NHibernate.Type.DbTimestampType.Seed(ISessionImplementor
session)
at NHibernate.Type.TimestampType.Next(Object current,
ISessionImplementor session)
at NHibernate.Engine.Versioning.Increment(Object version,
IVersionType versionType, ISessionImplementor session)
at
NHibernate.Event.Default.DefaultFlushEntityEventListener.GetNextVersion(FlushEntityEvent
event)
at
NHibernate.Event.Default.DefaultFlushEntityEventListener.ScheduleUpdate(FlushEntityEvent
event)
at
NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent
event)
at
NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent
event)
at
NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent
event)
at
NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent
event)
at NHibernate.Impl.SessionImpl.Flush()
We have checked that MSDTC is running fine. On test server, if we use
plain OracleConnection class within TransactionScope, then code is
working fine. Issue occurs when using NHibernate session only. We are
using:
NHibernate 3.0.0
Oracle Client 11.2.0.1
.NET 3.5 SP1
In the nhibernate logs, following are the last few lines when
transaction is suddenly rolled back without any error in the log:
2011-02-19 19:54:38,155 [9] DEBUG NHibernate.AdoNet.AbstractBatcher -
ExecuteNonQuery took 1 ms
2011-02-19 19:54:38,155 [9] DEBUG NHibernate.AdoNet.AbstractBatcher -
Closed IDbCommand, open IDbCommands: 0
2011-02-19 19:54:38,170 [9] DEBUG
NHibernate.Persister.Collection.ICollectionPersister - done deleting
collection
2011-02-19 19:54:38,170 [9] DEBUG
NHibernate.Persister.Collection.ICollectionPersister - Inserting
collection: [XXX.BusinessEntities.RolePlayer.PartyNameList#843]
2011-02-19 19:54:38,186 [9] DEBUG
NHibernate.Persister.Collection.ICollectionPersister - collection was
empty
2011-02-19 19:54:38,186 [9] DEBUG NHibernate.AdoNet.ConnectionManager
- registering flush end
2011-02-19 19:54:38,201 [9] DEBUG
NHibernate.Event.Default.AbstractFlushingEventListener - post flush
2011-02-19 19:54:38,201 [9] DEBUG NHibernate.Impl.SessionImpl -
[session-id=4391a921-5624-4552-bfa4-13b87f92b6cc] running
ISession.Dispose()
------- Here the first session is complete and second start starts
within same TransactionScope
2011-02-19 19:54:38,217 [9] DEBUG NHibernate.Impl.SessionImpl -
[session-id=5b33510a-593c-464c-98d9-f01eb52dce24] opened session at
timestamp: 634337420782, for session factory: [/
b72244cfece246d985ae4d4a2bbd9bd3]
2011-02-19 19:54:38,217 [9] DEBUG NHibernate.Impl.AbstractSessionImpl
- enlisted into DTC transaction: Serializable
2011-02-19 19:54:38,233 [9] DEBUG NHibernate.Engine.VersionValue -
version unsaved-value strategy UNDEFINED
2011-02-19 19:54:38,248 [9] DEBUG NHibernate.Engine.IdentifierValue -
unsaved-value: 0
2011-02-19 19:54:38,248 [9] DEBUG
NHibernate.Event.Default.AbstractSaveEventListener - transient
instance of: XXX.BusinessEntities.ScreenSectionConfirmation
2011-02-19 19:54:38,264 [9] DEBUG
NHibernate.Event.Default.DefaultMergeEventListener - merging transient
instance
2011-02-19 19:54:38,280 [9] DEBUG NHibernate.AdoNet.AbstractBatcher -
Opened new IDbCommand, open IDbCommands: 1
2011-02-19 19:54:38,280 [9] DEBUG NHibernate.AdoNet.AbstractBatcher -
Building an IDbCommand object for the SqlString: select
SEQ_SCR_SECTION_CONFIRM_ID.nextval from dual
2011-02-19 19:54:38,295 [9] DEBUG NHibernate.SQL - select
SEQ_SCR_SECTION_CONFIRM_ID.nextval from dual
2011-02-19 19:54:38,295 [9] DEBUG
NHibernate.Connection.DriverConnectionProvider - Obtaining
IDbConnection from Driver
2011-02-19 19:54:38,436 [9] DEBUG NHibernate.Impl.SessionImpl -
transaction completion
2011-02-19 19:54:38,436 [9] DEBUG NHibernate.AdoNet.ConnectionManager
- aggressively releasing database connection
2011-02-19 19:54:38,451 [9] DEBUG
NHibernate.Connection.ConnectionProvider - Closing connection
2011-02-19 19:54:38,451 [9] DEBUG NHibernate.Impl.AbstractSessionImpl
- rolled back DTC transaction
2011-02-19 19:54:38,467 [9] DEBUG NHibernate.Impl.SessionImpl -
transaction completion
2011-02-19 19:54:38,467 [9] DEBUG NHibernate.AdoNet.ConnectionManager
- aggressively releasing database connection
2011-02-19 19:54:38,483 [9] DEBUG NHibernate.Impl.AbstractSessionImpl
- rolled back DTC transaction
2011-02-19 19:54:38,483 [9] DEBUG NHibernate.Impl.SessionImpl -
transaction completion
2011-02-19 19:54:38,498 [9] DEBUG NHibernate.AdoNet.ConnectionManager
- aggressively releasing database connection
2011-02-19 19:54:38,498 [9] DEBUG NHibernate.Impl.SessionImpl -
[session-id=4391a921-5624-4552-bfa4-13b87f92b6cc] executing real
Dispose(True)
2011-02-19 19:54:38,514 [9] DEBUG NHibernate.Impl.SessionImpl -
closing session
2011-02-19 19:54:38,514 [9] DEBUG NHibernate.AdoNet.AbstractBatcher -
running BatcherImpl.Dispose(true)
2011-02-19 19:54:38,530 [9] DEBUG NHibernate.Impl.SessionImpl -
transaction completion
2011-02-19 19:54:38,545 [9] DEBUG NHibernate.AdoNet.ConnectionManager
- aggressively releasing database connection
2011-02-19 19:54:38,561 [9] DEBUG NHibernate.Impl.AbstractSessionImpl
- enlisted into DTC transaction: Serializable
2011-02-19 19:54:38,561 [9] DEBUG NHibernate.Impl.SessionImpl -
transaction completion
2011-02-19 19:54:38,576 [9] DEBUG NHibernate.AdoNet.ConnectionManager
- aggressively releasing database connection
2011-02-19 19:54:38,576 [9] DEBUG NHibernate.Impl.SessionImpl -
[session-id=5b33510a-593c-464c-98d9-f01eb52dce24] running
ISession.Dispose()
2011-02-19 19:54:38,592 [9] DEBUG NHibernate.Impl.SessionImpl -
[session-id=5b33510a-593c-464c-98d9-f01eb52dce24] executing real
Dispose(True)
2011-02-19 19:54:38,592 [9] DEBUG NHibernate.Impl.SessionImpl -
closing session
2011-02-19 19:54:38,608 [9] DEBUG NHibernate.AdoNet.AbstractBatcher -
running BatcherImpl.Dispose(true)
2011-02-19 19:54:38,608 [9] DEBUG NHibernate.AdoNet.AbstractBatcher -
Closed IDbCommand, open IDbCommands: 0