-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: SQL Server 2000 nvarchar field type
PostPosted: Thu Feb 24, 2005 6:51 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
Hibernate version: 2.1

Name and version of the database you are using: MS SQL Server 2000

Hi,

I'm using a SQL Server 2000 database with nvarchar fields.

In order to insert Unicode constants into the field using SQL, they are prepended with N.

i.e.

INSERT INTO mytable (my_unicode_field) VALUES (N'blah');

I haven't seen a way to configure Hibernate to generate this style of statement without me deriving my own StringType. Before I do, have I missed anything? Can Hibernate generate this kind of statement natively?

Thanks,

Phil


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 9:29 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Phil,

Just use parameterized queries (e.g. "INSERT INTO mytable (my_unicode_field) VALUES (?)" and then call setString(1, "blah") ) and the JDBC driver should take care of that for you.

Alin.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 9:48 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
I am actually using jTDS (0.9 in fact), and it doesn't appear to be doing this. Am I just missing a config option? I'm not using the charset property in the connection URL because the FAQ suggests I shouldn't need it.

Also, this wouldn't appear to account for the case where I create new objects which contain String properties, and save them back to the database.

I'm really lame at this whole area, so apologies if I'm missing something,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 9:53 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
"String properties which map to nvarchar fields" I should have said


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 9:57 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Phil,

Why do you say it "doesn't appear" to be sending Unicode values? What is the behavior you see?

You can use the SQL Server Profiler to take a peek at the communication going on between jTDS and SQL Server. You should see that the values have the N prepended. This is unless you specified sendStringParametersAsUnicode=false in the URL.

And as a side note, better get the latest version of jTDS. It should be more stable.

Alin.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 12:36 pm 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
Alin, you're right - according the SQL Profiler the values do have N prepended, but the value has been turned into junk by this stage already.

I ran a simple app which doesn't use Hibernate (using a PreparedStatement) and the data is inserted correctly (and looks fine in SQL Profiler).

When I perform the same PreparedStatement inside of Hibernate, the data is not inserted correctly (jTDS does correctly prepends the N to the query).

So I presume there's something in Hibernate I've misconfigured but I have no real idea what it could be, or where.

Cheers,

Phil


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 1:02 pm 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Maybe if you provided more detail on how Hibernate "turns to junk" the data you are inserting (i.e. how it looks as opposed to what it is supposed to be) I could help more.

Alin.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 6:50 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
Sorry for the delay in replying.

I've had trouble deterministically reproducing this error, especially since I've had to review my opinion that it was the SQL that was incorrect.

I'll do a bit more digging and get back to you.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 7:10 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
For what it's worth, I'm trying to insert Japanese data into an nvarchar field, but what ends up in my database *most of the time* appears to be an ASCII rendering of the byte values. Very occassionally, the correct Japanese data is actually inserted, although I can't reproduce the correct behaviour reliably.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 10:10 am 
Newbie

Joined: Thu Jun 03, 2004 7:02 am
Posts: 14
Location: UK
ok, all down to Eclipse being lame and breaking my character encodings. Hibernate and jTDS work perfectly.

Thanks for your time Alin (and for jTDS!).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.