-->
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.  [ 6 posts ] 
Author Message
 Post subject: Padding spaces using Oracle CHAR field
PostPosted: Mon Feb 13, 2006 6:56 am 
Newbie

Joined: Mon Feb 13, 2006 6:42 am
Posts: 5
Hi - I'm using Oracle 10g, Hibernate 2.1 and Spring framework 1.15, and have a currency table with a currency column of CHAR(3).

My mapping file maps this field as a String, length 3.

<property name="description" type="java.lang.String"
access="field"
column="CURRENCY_TYPE_CODE" length="3"
not-null="true" />


In my code, I am finding the currency using the find method:

return getHibernateTemplate().find("from CurrencyType ct where ct.description = ?", description);

This returns a list of CurrencyType objects, however, the Currency code field always seems to be padded to 12 chars - e.g. USD with 9 trailing spaces

I have tried changing the field to a VARCHAR2, which works fine, however for efficiency, we would prefer to use CHAR. Am I missing something in my mapping, or will this not actually work with a CHAR data type?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 12:30 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

The space are appended in the DB. Hibernate doesnt do anything to it.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 14, 2006 10:36 am 
Newbie

Joined: Mon Feb 13, 2006 6:42 am
Posts: 5
Hi - Could you explain this in more detail please?

The column itself is CHAR(3), so I would expect only 3 characters to be returned.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 10:02 am 
Newbie

Joined: Mon Feb 13, 2006 6:42 am
Posts: 5
Someone mentioned this might be something to do with Unicode characters - can anyone offer any more insight ? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 1:59 pm 
Newbie

Joined: Wed Jun 07, 2006 1:57 pm
Posts: 1
Check out http://forum.hibernate.org/viewtopic.php?t=928294, which explains the problem and offers a user type mapping to solve it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 07, 2006 2:37 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
I think the previous replies have overlooked his point about getting a string of length 12 back for a column defined and mapped with a length of 3. There is something else going on here. He is not simply asking about padding that is applied for fixed length fields.

Have you double-checked to make sure the table definition is actually what you think it is? This behaviour doesn't make sense.


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