-->
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: Problem with white spaces being added to the database values
PostPosted: Fri Jul 14, 2006 3:10 pm 
Newbie

Joined: Fri Jul 07, 2006 9:53 am
Posts: 11
Hello.

Im having a problem with hibernate right now. We are using it in a web app with nothing really special. Just forms being used a lot and we have hibernate to handle the database end. It is saving information into the database, but whenever I save a string value into the database, it adds up to 61 white spaces at the end.

Now when I say 'up to', it adds on 61-(length of string) total white spaces. that number always stays the same. But if its an integer being saved, it doesnt do anything wrong at all. No white spaces added. Ive tried setting the maxlength in teh xml config for that class type and it doesnt help. Ive also tried doing a .trim() value for the object before saving into the database, and it still does it.

Ive even set it up to where i put a .trim() on the string right before it is saved, then i save it. after that , i retrieve it and it has the white spaces in it.

Ive tried poking around online to see if I could find any related issues, but I have not. If you have any thoughts, please let me know. Thank you.

Marcel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 4:31 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
is your database padding it, like say in the char field type?

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 4:37 pm 
Newbie

Joined: Fri Jul 07, 2006 9:53 am
Posts: 11
not that i know of. Im not really 100% sure how to check to see if it is set to actually pad them. but that would make sense because its constantly padding up to 61 characters. Do you know where to actually check for that though?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 4:57 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
well I'll tell you this

Hibernate does not pad String data types by itself, either on the way in or out. It uses the getters of objects to get the values for the sql queries it runs, so if you have trim statements in the getters, you can guarantee your data is getting to the database w/o any padding.

If you use custom user types, you can define padding in there, but I'd think you'd know if you were.

Basically, if you are saving trimmed Strings, and getting them back padded, then your database is padding them. A typical field type in a db that pads values is CHAR type.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 6:45 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
change the coulmn datatype from

char
to
varchar

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 6:46 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
change the datatype from char to varchar

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 8:21 am 
Newbie

Joined: Fri Jul 07, 2006 9:53 am
Posts: 11
Thank you for both of your responses, but here is the problem I'm in. While doing a .trim() when i get the data would work for this program I'm working on now, but I need other programs to work off the same database with the same data. Unfortunately, I cant go back into those programs and add .trim()'s to everything :(. Also, the datatypes in the database were already varchars and I'm still getting the padding. Any thoughts? Thank you again for your help.


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.