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.  [ 3 posts ] 
Author Message
 Post subject: varchar field filled with space - SQL Server
PostPosted: Mon Jul 10, 2006 2:34 am 
Newbie

Joined: Mon Jun 26, 2006 4:26 am
Posts: 2
Hi,
I am using hibernate to connect with SQLServer 2005. I am having a table with some varchar(10) fields.
While inserting/updating to this table, I am giving the value to the Hibernate object as 'abc'. After calling update, the valus in the database is
'abc '. It put 7 spaces to fill the varchar(10).
Whats the prob, and how could I resolve it?
I have checked wheter spaces are there while assigning data to object, but no.

hbm.xml
----------
<class name="TblTab" table="TBLTAB">
<id name="toolNum" column="TOOL_NUM" type="java.lang.Long">
<generator class="identity"/>
</id>

<property name="toolId" column="TOOL_ID" type="java.lang.String" />
<property name="machId" column="MACH_ID" type="java.lang.String" />

In Class
------
private java.lang.String toolId;
private java.lang.String machId;


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 3:49 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I'm pretty sure you should look at your db configuration, and in the sqlserver doc about fields that're typed varchar(). Maybe it's fixed-width, so It's padded by the dbms when receiving the query and before executing it...

In fact, Hibernate does not apply anything special to strings, as reminded here by a member of the Hibernate Team :
http://forum.hibernate.org/viewtopic.ph ... 51#2192051

This automatic padding is also done by Oracle. I seem to remember a thread talking about that, but I can't find it again. I's say it was with Oracle 8 maybe.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 4:32 am 
Newbie

Joined: Mon Jun 26, 2006 4:26 am
Posts: 2
I was using jdbc-odbc bridge for connectivity. I just changed it to use "microsoft.sqlserver.jdbc.SQLServerDriver". Now the problem solved. No other changes made in code, DB or hbm file


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