Search code examples
c#nhibernatenservicebushbm

Modifying how nHibernate saves Saga data in nServiceBus


I'm having an issue where I'm sending a message to nServiceBus with a message data field of variable length. nServiceBus is using nHibernate to create a table called

[NServiceBus].[PendingMentorEmailSagaData] 

from a class called PendingMentorEmailSagaData . The message field is however getting set to nvarchar(255), I am looking for a way to have it set to nvarchar(MAX).

I've tried using an embedded hbm file, but am getting a "persistent class PendingMentorEmailSagaData not found" error.

This probably means I can't figure out what class to set the file too.

The hbm file:

<?xml version="1.0" encoding="utf-8" ?>

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
      <class name="PendingMentorEmailSagaData">
        <id name="Id" />
        <property name="OriginalMessageId" />
        <property name="Originator" />
        <property name="PendingMentorEmailCommandId" />
        <property name="JobBoardCode" />
      </class>
    </hibernate-mapping>

PendingMentorEmailSagaData is the name of the saga's data class.


Solution

    1. Create a PendingMentorEmailSagaData.hbm.xml file in the same project that the saga exists on, eg:
        <?xml version="1.0" encoding="utf-8"?>
        <hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
          <class name="MY_NAMESPACE.PendingMentorEmailSagaData, MY_ASSEMBLY_NAME" table="PendingMentorEmailSagaData" dynamic-update="true" optimistic-lock="all">
            <id name="Id" type="Guid">
              <generator class="assigned" />
            </id>
            <property name="Originator" />
            <property name="OriginalMessageId" />
            <property name="LargeText" type="StringClob" />
          </class>
        </hibernate-mapping>
    

    2. Mark that file as an Embedded Resource