NH 3.3.0GA Bug with NVarChar(MAX)/NText?

1,302 views
Skip to first unread message

nfplee

unread,
Apr 26, 2012, 8:14:35 AM4/26/12
to nhibernate-...@googlegroups.com
Hi, i have just upgraded an application to version 3.3.0GA and have notificed a bug when inserting large amounts of data into a NVarChar(MAX) field in the database (also tested with NText). It throws the following error:

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

With the following mapping:

<property name="Body">
  <column name="Body" />
</property>

But it works fine with the following:

<property name="Body">
  <column name="Body" length="2147483647" />
</property>

The original mapping worked fine before. This looks like a pretty bad bug to me. I was wondering if anyone else could confirm this.

Thanks

Richard Brown

unread,
Apr 26, 2012, 8:20:00 AM4/26/12
to nhibernate-...@googlegroups.com
Hi,

I think it will be related to this fix:

I suspect you'll need to specify the StringClob type in the mapping.

Regards,
    Richard

Darren Kopp

unread,
Apr 27, 2012, 2:08:33 AM4/27/12
to nhibernate-...@googlegroups.com
Wait, are you saying parameter length of 10000 no longer makes the parameter nvarchar(max)? 


On Thursday, April 26, 2012 6:20:00 AM UTC-6, FlukeFan wrote:
Hi,

I think it will be related to this fix:

I suspect you'll need to specify the StringClob type in the mapping.

Regards,
    Richard

Richard Brown

unread,
Apr 27, 2012, 3:10:23 AM4/27/12
to nhibernate-...@googlegroups.com
I think the SchemaExport will still generate a VARCHAR(MAX) in the schema, but persisted changes would need to be less than the specified length (10,000 characters in your example).

Oskar Berggren

unread,
Apr 27, 2012, 3:50:00 AM4/27/12
to nhibernate-...@googlegroups.com
Den 26 april 2012 14:14 skrev nfplee <nfp...@hotmail.com>:
> Hi, i have just upgraded an application to version 3.3.0GA and have
> notificed a bug when inserting large amounts of data into a NVarChar(MAX)
> field in the database (also tested with NText). It throws the following
> error:
>
> The length of the string value exceeds the length configured in the
> mapping/parameter.
>
> With the following mapping:
>
> <property name="Body">
>   <column name="Body" />
> </property>


Not specifying a length makes NHibernate default to 4000 (unicode) characters.


>
> The original mapping worked fine before. This looks like a pretty bad bug to
> me. I was wondering if anyone else could confirm this.


What happened in 3.2 etc. was that your string was being silently
truncated to 4000 characters, or whatever length you specified.

Intended behavior in 3.3GA
SchemaExport use the defined length and create nvarchar(max) if longer
than 4000 characters (report a bug if this is not the case).
SQL string parameters will have their size rounded up to 4000
characters, unless more is required in which case it will be rounded
up to Int.MaxValue/2 (on ms sql server).
When setting the value of a string parameter, NHibernate will throw if
the string is longer than the defined length of the string parameter
to prevent ADO.NET from performing silent truncation of the string.


/Oskar

Fabio Maulo

unread,
Apr 27, 2012, 5:17:48 AM4/27/12
to nhibernate-...@googlegroups.com
It is "just" a breaking change reported in the releasenote.txt shipped with the binaries.
--
Fabio Maulo

Reply all
Reply to author
Forward
0 new messages