Exceptions when using NHibernatePersistence

405 views
Skip to first unread message

Martin Nilsson

unread,
Jan 6, 2015, 5:13:35 AM1/6/15
to particularsoft.
I'm trying to replace RDB with SQL server but I get this exception when processing message.

EXCEPTION OCCURRED:NHibernate.TransactionException: Begin failed with SQL exception ---> System.InvalidOperationException: SqlConnection does not support parallel transactions.

This is my Endpoint config

public class EndpointConfig : IConfigureThisEndpoint, AsA_Worker
{
public void Customize(BusConfiguration configuration)
{
LogManager.Use<NLogFactory>();

var endpointName = GetType().Namespace;
configuration.EndpointName(endpointName);

configuration.AssembliesToScan(AllAssemblies.Except("SagaProcessing.vshost.exe"));

configuration.Conventions().DefiningEventsAs(t => typeof (IDomainEvent).IsAssignableFrom(t));
configuration.Conventions().DefiningMessagesAs(t => typeof (IDomainMessage).IsAssignableFrom(t));
configuration.Conventions().DefiningCommandsAs(t => typeof (IDomainCommand).IsAssignableFrom(t));

configuration.UseTransport<SqlServerTransport>();
configuration.EnableInstallers();
configuration.UseSerialization<JsonSerializer>();
configuration.Transactions().Enable();
configuration.Transactions().DisableDistributedTransactions();
configuration.UsePersistence<NHibernatePersistence>()
            .For(Storage.Subscriptions,
                    Storage.Timeouts,
                    Storage.Sagas,
                    Storage.Outbox);
configuration.EnableOutbox();
}
}

If I remove the Outbox feature I get this exception instead.

EXCEPTION OCCURRED:System.InvalidOperationException: ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.  The Transaction property of the command has not been initialized.

I found this issue, that has the same behaviour but its status is Closed.

Attached are the full stacktraces.

NSB versions

<package id="NServiceBus" version="5.1.2" targetFramework="net451" />
<package id="NServiceBus.Azure" version="6.1.3" targetFramework="net451" />
<package id="NServiceBus.Hosting.Azure" version="6.1.3" targetFramework="net451" />
<package id="NServiceBus.Hosting.Azure.HostProcess" version="6.1.3" targetFramework="net451" />
<package id="NServiceBus.NHibernate" version="6.0.1" targetFramework="net451" />
<package id="NServiceBus.NLog" version="1.0.0" targetFramework="net451" />
<package id="NServiceBus.SqlServer" version="2.0.2" targetFramework="net451" />
  

Any guidance?
nsb_parallel_trans.txt
nsb_trans_not_initialized.txt

Szymon Pobiega

unread,
Jan 7, 2015, 3:36:54 AM1/7/15
to particula...@googlegroups.com
Hey Martin

Are you using shared session feature to persist your own object via NHibernate? Also, I assume you only use Azure for hosting, not for transport purposes.

Szymon

--
You received this message because you are subscribed to the Google Groups "Particular Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftw...@googlegroups.com.
To post to this group, send email to particula...@googlegroups.com.
Visit this group at http://groups.google.com/group/particularsoftware.
To view this discussion on the web visit https://groups.google.com/d/msgid/particularsoftware/CABbQ0ftUxxZJ0zPQ1eshYv%3D3D-YcbtMceOdqaDEbias_E91W-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Szymon Pobiega

unread,
Jan 7, 2015, 3:41:09 AM1/7/15
to particula...@googlegroups.com
Also, does it happen for all messages or e.g. for sagas only?

Szymon

Martin Nilsson

unread,
Jan 7, 2015, 7:03:00 AM1/7/15
to particularsoft.
No persisting of own objects in the sagas. 
More or less every handler in my sagas is updating the saga state and then send a command on the bus
Something like this:

public void Handle(CustomerRegistered message)
{
Data.TenancyId = message.TenancyId;
Data.Email = message.Email;
...
Bus.Send(aCommand);
}

The saga data contains custom types (eg TenancyId), which are mapped to separate tables. If that could make any difference?
I'm in the process of removing these types and map them to .Net types (mainly Guids) instead in the data class.

Only using Azure for hosting yes.

So far I have only seen it in my sagas.

Martin Nilsson

unread,
Jan 7, 2015, 2:48:44 PM1/7/15
to particularsoft.
The error happens when trying to find the saga. See attached file for details.

System.InvalidOperationException: ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.  The Transaction property of the command has not been initialized.
   at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
   ...
   at NServiceBus.SagaPersisters.NHibernate.SagaPersister.NServiceBus.Saga.ISagaPersister.Get[T](String property, Object value) in c:\BuildAgent\work\7292bb915dd8fc2\src\NServiceBus.NHibernate\SagaPersisters\SagaPersister.cs:line 56
   at NServiceBus.Sagas.PropertySagaFinder`1.Find(IBuilder builder, SagaFinderDefinition finderDefinition, LogicalMessage message) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Sagas\PropertySagaFinder.cs:line 32
   at NServiceBus.SagaPersistenceBehavior.TryLoadSagaEntity(SagaMetadata metadata, LogicalMessage message) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Sagas\SagaPersistenceBehavior.cs:line 260
   at NServiceBus.SagaPersistenceBehavior.Invoke(IncomingContext context, Action next) in c:\BuildAgent\work\1b05a2fea6e4cd32\src\NServiceBus.Core\Sagas\SagaPersistenceBehavior.cs:line 52

RoomProductsTaxSaga.ConfigureHowToFindSaga:
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<RoomProductsTaxSagaData> mapper)
{
   mapper.ConfigureMapping<PreferenceItemValueCreated>(s =>
                                                       s.CustomerTenancyId == null
                                                          ? default(Guid)
                                                          : s.CustomerTenancyId.Id)
         .ToSaga(m => m.TenancyId);
   mapper.ConfigureMapping<ValueChangedForItem>(s => s.Id == null
                                                        ? default(Guid)
                                                        : s.Id.Id)
         .ToSaga(m => m.RoomTaxCodePreferenceItemValueId);
}
nsb_trans_not_initialized_finder_st.txt

Justin Alexander

unread,
Jan 8, 2015, 4:51:32 PM1/8/15
to particula...@googlegroups.com
Hi Martin,

Can you share some details regarding your Saga Data class definition? Is Data.TenancyID a native/primitive system type or is that derived from a custom class within your own domain?

Thanks,

~Justin
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftware+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Particular Software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftware+unsub...@googlegroups.com.

To post to this group, send email to particula...@googlegroups.com.
Visit this group at http://groups.google.com/group/particularsoftware.

Martin Nilsson

unread,
Jan 8, 2015, 5:27:08 PM1/8/15
to particula...@googlegroups.com
Previous it was a custom class but now it's a simple Guid. I have recreated all my tables as well but no luck. 
I have this exception in another project/process as well with two simple eventhandlers.
To unsubscribe from this group and stop receiving emails from it, send an email to particularsoftw...@googlegroups.com.

To post to this group, send email to particula...@googlegroups.com.
Visit this group at http://groups.google.com/group/particularsoftware.

Szymon Pobiega

unread,
Jan 9, 2015, 4:52:47 AM1/9/15
to particula...@googlegroups.com
Hey Martin,

Currently NHibernate can only work with SQLServer transport by sharing same TransactionScope. Can you try removing

configuration.Transactions().DisableDistributedTransactions();

and see if it helps? It would not escalate to DTC since SQL driver uses promotable enlistement and both SQL and NHibernate use same connection. Also, I've created an issue https://github.com/Particular/NServiceBus.NHibernate/issues/77 to track progress on fixing this bug.

Hope that helps,
Szymon

Martin Nilsson

unread,
Jan 9, 2015, 5:02:57 PM1/9/15
to particularsoft.
Removing "configuration.Transactions().DisableDistributedTransactions();" fixed the issue. I can't use DTC but it is like you say, transaction is not promoted to a distributed transaction.

Reply all
Reply to author
Forward
0 new messages