nvarvchar(max) issues

170 views
Skip to first unread message

Ramon Smits

unread,
May 17, 2013, 10:54:01 AM5/17/13
to nservicebus, nhusers

This is crossposted to NServiceBus and NHUsers mailing list.


I have a custom mapping (hbm.xml) for a saga class. One property should be mapped to a nvarchar(max) column.

I started with the following property type:

    <property name="Data" type="StringClob"/>


This created the correct schema but when data is getting larger then 4000 characters I'm getting the following exception:

     NHibernate.HibernateException
     The length of the string value exceeds the length configured in the mapping/parameter.


During initialization I see that the property is mapped but I don't see a reference to StringClobType.


In the log I see the following:

     [Debug] binding '.....' to parameter: 4  (NHibernate.Type.StringType)


So it seems that although the property type is set to StringClob that this type is not used.


I tried several different mappings that are mentioned in the following posts but without success:




Does anybody have a solution for this problem?



-- Ramon

Tyler Burd

unread,
May 17, 2013, 11:08:10 AM5/17/13
to nserv...@yahoogroups.com, nhusers

Assuming you are using a recent version of NHibernate, all you need to do is set a “length” attribute to something higher than 4000.  You can also omit the type=”StringClob”; that’s for ntext fields.

 

So your mapping should look like this:

<property name="Data" length="10000"/>

 

-Tyler Burd

Ramon Smits

unread,
May 20, 2013, 6:13:06 AM5/20/13
to nservicebus, nhusers
The problem was that the mapping was previously an embedded resource, creating the table column with the correct type. Then the mapping was not an embedded resource any more and resided on the file system. NServiceBus initializes NHibernate by passing a set of assemblies to scan so this did not work resulting in the normal behavior of nservicebus that resulted in using nvarchar(255).

So the problem was not NHibernate, but the fact that the whole mapping was not loaded.


-- Ramon




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply all
Reply to author
Forward
0 new messages