aspose file tools*
The moose likes Object Relational Mapping and the fly likes ntext problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "ntext problem" Watch "ntext problem" New topic
Author

ntext problem

peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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 ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
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}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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: 240
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: 240
NHibernate can use StringClob type, but how about Hibernate?
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
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: 240
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: 240
some typo error.

in cfg.xml
should use "SQLServerDialectNText" instead of "SQLServerDialect"
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by peter tong:

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: 240
if using nvarchar(max), then how to map it in hbm.xml file?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I'd guess you map it to String and let the driver worry about the mechanics of it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ntext problem