NHibernate and large text fields gotchas

There are two gotchas associated with working with large text fields with NHibernate.

The first is that you must specify type="StringClob" (or ColumnType = "StringClob" in Active Record), if you are using SQL Server, since NHibernate needs to set the Size property on the parameters.

The second is that if you plan of letting NHibernate generate your schema, you need to specify sql-type="NTEXT" (or SqlType="NTEXT" in Active Record), otherwise NHibernate will generate an NVARCHAR field.

Print | posted on Saturday, December 30, 2006 4:19 PM

Feedback


Gravatar

#  1/2/2007 8:13 AM Ken Egozi

afaik, when using SQL-Server 2005 and it's dialect, you can spare the "StringClob" thingie. SQL-Server 2005 allows nvarchar(MAX), which gives you the length of ntext, the full-text indexing ability, and the nvarchar syntax (like, '%', concatenation, etc.)
The trick is the elimination of the "record cannot span pages". since now it can, you can use a "normal" field, with no length limit. (the actual length limit of about 4 zilion characters is not really a limit).


Gravatar

#  1/2/2007 8:42 AM Ayende Rahien

Now that is a nice thing to know.
I always assumed that NVARCHAR(MAX) == NVARCHAR(4000).
This still doesn't solve the first problem, though, since the truncation is happening at the client level, IMO.


Gravatar

#  1/2/2007 12:30 PM Josh Robb

The truncation only occurs if you have prepared statements enabled. (AFAIK). Sergay and I discussed this on the NH list about this a while ago. If prepared statements are enabled then NH sets the parameter size before executing the statement - which causes ADO.NET to truncate values. Otherwise they are passed intact to SqlServer to process. (At least - this is what I remember).

NVARCHAR(MAX) is seriously - seriously cool!

Comments have been closed on this topic.