Error after upgrading to NHibernate 3.0 XML parsing: line 1, character 4000, unexpected end of input -
i have sql2008 db has column type of xml. using nhibernate 2.5 can save column no problems.
i've dropped in nhibernate 3.0 dlls , i'm getting above errors?
my mapping file doesn't have type against column surely nhibernate should pick xml data type (i'm using sql 2008 dialect) ?
4000 seems suspicious length, i.e length of varchar column in sql.
i see there few articles mapping xml columns using custom usertypes, etc.
how come worked in 2.5 , doesn't in 3.0 ? don't need special handling. column gets used string everywhere.
the reason behavior changed 2.x 3.0.0 due a code commit on nhibernate.driver.sqlclientdriver
, turned on of behavior of enabling prepare_sql
configuration in order resolve issue caching of query plans.
a c# string
property mapped column has no other type
specified in mapping treated nhibernate.sqltypes.stringsqltype
, given 4000 character limit driver:
from nhibernate.sqltypes.stringsqltype
:
/// <remarks> /// can store length of string <see cref="idbdataparameter"/> can hold. /// if no value provided length <c>driver</c> responsible /// setting properties on <see cref="idbdataparameter"/> correctly. /// </remarks>
so, can see code below driver (nhibernate.driver.sqlclientdriver
), maps default string
property length of 4000 characters.
/* snip */ private const int maxansistringsize = 8000; private const int maxbinarysize = maxansistringsize; private const int maxstringsize = maxansistringsize / 2; private const int maxbinaryblobsize = int.maxvalue; private const int maxstringclobsize = maxbinaryblobsize / 2; /* snip */ private static void setdefaultparametersize(idbdataparameter dbparam, sqltype sqltype) { switch (dbparam.dbtype) { /* snip */ case dbtype.string: case dbtype.stringfixedlength: dbparam.size = istext(dbparam, sqltype) ? maxstringclobsize : maxstringsize; break; /* snip */ } }
for configurations prepare_sql
set false
, nh 3.0.0 brings setdefaultparametersize
method play not before
as noted, can use nh-3.0.0-native support sql server xml
datatype (thanks nh-866), so:
<property name="data" type="xml" not-null="true" />
or more explicitly, equivalently:
<property name="data" type="xmldoc" not-null="true"> <column name="data" sql-type="xmlsql" /> </property>
but using nhibernate.type.xmldoctype
expects property type of c# type xmldocument
- leading cast exception.
you xmldocument.innerxml
fix mentioned, that's lot of unnecessary transformation string doc , back. i've used following mapping keep domain property string:
<property name="data" type="stringclob" not-null="true"> <column name="data" sql-type="xmlsql" /> </property>
using nhibernate.type.stringclobtype
return true istext(dbparam, sqltype)
call in driver snippet above, giving max character length of int.maxvalue / 2
- 2gb of string data.
Comments
Post a Comment