Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ntext problem

 
peter tong
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
peter tong
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NHibernate can use StringClob type, but how about Hibernate?
 
peter tong
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
some typo error.

in cfg.xml
should use "SQLServerDialectNText" instead of "SQLServerDialect"
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if using nvarchar(max), then how to map it in hbm.xml file?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd guess you map it to String and let the driver worry about the mechanics of it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic