-->
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.  [ 7 posts ] 
Author Message
 Post subject: Mapping nvarchar SQL Server with jTDS not trimmed
PostPosted: Mon Feb 28, 2005 8:11 am 
Newbie

Joined: Mon Feb 28, 2005 7:57 am
Posts: 7
Location: Toulouse, France
Hello!

I've got a problem of mapping using hibernate 2.17 on SQL Server 7 with the latest jTDS version


In my database i've got a column containing a nvarchar(256), mapped on a String with this :
<property name="comment" type="string" column="S***T" />

But the problem is that values returned during a load aren't trimmed (filled with spaces to 256 chars)


The cfg.xml file looks like this :

...
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://myServer:1234;myBase</property>
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.connection.username ... password ... domain ... </property>

<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.show_sql">false</property>
...


Any help could be precious !


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 5:26 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Are you sure the column type is NVARCHAR and not NCHAR? If so, could you provide the generated SQL and any other information you might find interesting?

Alin.


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

Joined: Mon Feb 28, 2005 7:57 am
Posts: 7
Location: Toulouse, France
Hello

The database already exists and cannot easily be modified

The script for this particular table (if it can help) is :

create table T_SIAM (
SIAM_YEAR int not null,
SIAM_MONTH int not null,
SIAM_OWNER int not null,
SIAM_VERSION int not null,
SIAM_DATE_VERSION datetime not null,
SIAM_AUTHOR int not null,
SIAM_ETAT char(1) not null,
SIAM_COMMENT nvarchar(512) null,
SIAM_MOTIF nvarchar(512) null,
SIAM_DATE_INTEGRATION datetime null,
SIAM_INTEGRE bit not null,
SIAM_GROUP nvarchar(8) not null,
SIAM_IMPUTATION text not null,
constraint PK_T_SIAM primary key (SIAM_YEAR, SIAM_MONTH, SIAM_OWNER, SIAM_VERSION)
)


And with show_sql set to ture, I got this :

Hibernate:
select
siam0_.SIAM_YEAR as SIAM_YEAR0_,
siam0_.SIAM_MONTH as SIAM_MONTH0_,
siam0_.SIAM_OWNER as SIAM_OWNER0_,
siam0_.SIAM_VERSION as SIAM_VER4_0_,
siam0_.SIAM_DATE_VERSION as SIAM_DAT5_0_,
siam0_.SIAM_AUTHOR as SIAM_AUT6_0_,
siam0_.SIAM_ETAT as SIAM_ETAT0_,
siam0_.SIAM_COMMENT as SIAM_COM8_0_,
siam0_.SIAM_MOTIF as SIAM_MOTIF0_,

siam0_.SIAM_DATE_INTEGRATION as SIAM_DA10_0_,
siam0_.SIAM_INTEGRE as SIAM_IN11_0_,
siam0_.SIAM_GROUP as SIAM_GROUP0_,
siam0_.SIAM_IMPUTATION as SIAM_IM13_0_

from T_SIAM siam0_
where siam0_.SIAM_YEAR=?
and siam0_.SIAM_MONTH=?
and siam0_.SIAM_OWNER=?
and siam0_.SIAM_VERSION=?

Hope it can help you in helping me :)

Axel.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 5:59 am 
jTDS Developer
jTDS Developer

Joined: Tue Feb 24, 2004 5:36 pm
Posts: 70
Location: Bucharest, Romania
Weird. There's only one possibility that comes to mind: are the character values stored padded with blanks (e.g. "value ")? In this case the driver would simply return the content, no trimming done.

Alin.


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

Joined: Mon Feb 28, 2005 7:57 am
Posts: 7
Location: Toulouse, France
The values in the database aren't padded with blanks, so the problem occurs during read and not during write.

The solution I'm currently using isn't very clean : I trim the String in the setters of my domain objects. So the final behaviour is the same than if the String wasn't filled with spaces.

I don't see anything that could explain that and I am looking for a cleaner solution !!

Thanks

Axel.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 7:55 am 
jTDS Developer
jTDS Developer

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

You could enable jTDS logging (please note that it will produce a lot of output) by appending "logFile=some.log" to the URL and look at the relevant SELECT and its response see if the padding comes from the server or not. jTDS definitely doesn't pad values.

Alin.


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

Joined: Mon Feb 28, 2005 7:57 am
Posts: 7
Location: Toulouse, France
Not a lot of time now on this project but I will try this asap and tell you what i'll found.

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.