Question

I am getting error when i trying to store this sagadata and that too because of List. As soon as i remove this List it can store the data.

public virtual Guid Id { get; set; }
public virtual string Originator { get; set; }
public virtual string OriginalMessageId { get; set; }
public virtual string TransactionReference { get; set; }
public virtual string CvvNumber { get; set; }
public virtual List<string> SupplementCodes { get; set; }
Was it helpful?

Solution

It has been a long time since I have worked with NHibernate for saga storage - this is precisely why I didn't like it! During NServiceBus 2.0 I wrote my own saga handler that uses XML serialization instead. RavenDB, being a document database, doesn't have any of these problems.

However, from memory, what is happening is that NHibernate can't store the list of strings within one table, so it needs to be able to create a second table to normalize the data.

If we were creating this manually, we would create a table with SagaId and StringValue and call it SagaSupplementCode. NHibernate can't quiet figure out how to do this.

If you created something like this, I think NHibernate would be able to store it.

public class MySagaData
{
public virtual Guid Id { get; set; }
public virtual string Originator { get; set; }
public virtual string OriginalMessageId { get; set; }
public virtual string TransactionReference { get; set; }
public virtual string CvvNumber { get; set; }
public virtual List<SupplementCode> SupplementCodes { get; set; }
}

public class SupplementCode
{
    public virtual Guid Id { get; set; }
    public virtual string Code { get; set; }
}

The addition of the class gives NHibernate something to base the table name off of and relate to the saga data table. Note that you must have the Id column, and it must be virtual in order for the automapping to work. (Thanks Andreas for the comment!)

Alternate Method

Contention on the saga data can be a major problem with NHibernate if your saga data gets split into multiple tables like this, because the database must now hold locks on multiple tables.

"SupplementCodes" sounds like something that's fairly basic. If you could change your saga storage to use a comma separated list in one string, then NHiberante would be able to store it in one table and you'd probably be better off from a performance and locking perspective.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top