I find that ntext datatype can only save maximun 4000 character, why this is the case and any solution? in mapping file, I try to set type="text" but it does not help.
The SQL Server data type ntext supports 1,073,741,823 unicode characters. I'm guessing something is treating your ntext as an nvarchar data type (since 4000 characters is that datatype's limit) Not likely to be whatever ORM framework your are using, since Strings are all that will deal with. [ October 10, 2008: Message edited by: Paul Sturrock ]
I have set show-sql="true" and from the sql generated, I see the statement is something like update [tablename] set (fieldname1, fieldname2) values (?, ?)!!
but for ntext field, these statement does not work. the generated sql show have some statement like WRITETEXT {table.column text_ptr} [WITH LOG] {data}
Can you change the data type? As of SQL Server 2005 ntext support is being discontinued by Microsoft in favour of nvarchar(). Might be an easy way to fix it.
That a side, the WRITETEXT function shouldn't be truncating the data. You might try sticking a break point in the Hibernate code where the value is bound, see what data finds its way into this. WHich JDBC driver are you using?
peter tong
Ranch Hand
Joined: Mar 15, 2008
Posts: 234
posted
0
I use sqljdbc.jar, maybe I have a typo, there is no writetext function generated, but only update tablename set fieldname1, fieldname2 values ?,? is generated.
nvarchar can only have maximun 4000 characters, isn't it? or nvarchar(max) can help?
peter tong
Ranch Hand
Joined: Mar 15, 2008
Posts: 234
posted
0
NHibernate can use StringClob type, but how about Hibernate?
peter tong
Ranch Hand
Joined: Mar 15, 2008
Posts: 234
posted
0
it seems we can register a data type in hibernate using RegisterColumnType, but I don't know the implementation detail, anyone can help?
peter tong
Ranch Hand
Joined: Mar 15, 2008
Posts: 234
posted
0
it seems so sad that no one can help, anyway I find the solution.
public class SQLServerDialectNText extends SQLServerDialect { private static final org.apache.log4j.Logger _log = org.apache.log4j.Logger.getLogger(SQLServerDialectNText.class);
public SQLServerDialectNText(){ super(); registerColumnType( Types.LONGVARCHAR, "ntext" ); _log.debug(" constructor of SQLServerDialectNText"); } }
if using jdk1.6, should use LONGNVARCHAR instead of LONGVARCHAR
then in cfg.xml, dialect should use "SQLServerDialectNText" instead of "SQLServerDialectNText"
peter tong
Ranch Hand
Joined: Mar 15, 2008
Posts: 234
posted
0
some typo error.
in cfg.xml should use "SQLServerDialectNText" instead of "SQLServerDialect"
nvarchar can only have maximun 4000 characters, isn't it? or nvarchar(max) can help?
No, it can use much more than that. Since ntext is soon to be removed from SQL Server, I wouldn't create new fields using it if I could at all avoid it.
peter tong
Ranch Hand
Joined: Mar 15, 2008
Posts: 234
posted
0
if using nvarchar(max), then how to map it in hbm.xml file?