views:

13

answers:

1

Hello,

I'm in troubles with TransactionPropagation.NotSupported. I believed that this propagation causes that the code is executed within no transaction. Means that when I marked the specific method, the current transaction will be suspended and the code will be executed without any transaction.

The current version of spring.net creates new transaction instead. See the following code:

[Test]
public void A() {
        TransactionTemplate template = new TransactionTemplate(TransactionManager) {
            PropagationBehavior = TransactionPropagation.NotSupported
        };
        template.Execute(delegate {
            Assert.AreEqual(0, 
               SessionFactory.GetCurrentSession().Linq<XXX>().
               Where(t => t.Id.Equals(YYY)).ToList().Count);
            return null;
        });
}

I hoped that this notation causes that linq query is executed without transaction and it'll throw the new exception. But the log showed that it creates both new session and transaction automatically.

I've find out this issue when I marked any method by mentioned annotation and despite the annotation the LINQ query inside was correctly executed.

The question is: how can I mark the method to it's doesn't use the transaction at all? I don't want to use propagation never as I want the current transaction would be suspended.

My project has the business code flow, there is transaction handling, and I want to mark any parts to be certainly non-transactional.

A: 

You mention being able to tell from the log that a new transaction is started. What log, the database or the application? What database are you using? Some databases won't let you run a query outside a transaction at all, so would just start one internally for you...


Update:

Your issues looks similar to this one:

https://jira.springframework.org/browse/SPRNET-1307?page=com.atlassian.jira.plugin.ext.bamboo%3Abamboo-build-results-tabpanel#issue-tabs

I would make sure you are running the version of Spring.NET that has this fix in it (looks like v 1.3.1 or greater?)

Also, you could try manually suppressing the transaction and see if that fixes the behavior:

using(var tx = new TransactionScope(TransactionScopeOption.Suppress))
{
    // make DB call...
}
rally25rs
Log4net log generated by my test. NHibernate log some useful informations in the scope of DEBUG mode. I'm using MSSQL.
Martin Podval
Thank you. I have already found this issue, but I didn't know how to define or use TransactionScopeOption.Suppress with using spring.net transaction and nhibernate. I don't know where to inject it, I'm using yesterday's spring.net build so the spring.net contains repaired behavior.
Martin Podval