| Author |
Hibernate saves nvarchar values with a trailing space
|
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
Hi All,
I am using Hibernate. When i save the data it saves nvarchar values with a trailing space.
How can I eliminate this ?
Thanks
|
 |
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
Hi All,
If I have posted the question in the wrong forum please let me know.
Thanks
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Nothing to do with Hibernate I think. What makes you think it is Hiberate that is causing the problem?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
Thanks for the reply.
I have written stuff without using Hibernate and that does not add any space. Plus I am using trim (in the setter) on the value being stored to try to eliminate the space.
And I also found that 2 people had the same concern using Hibernate in the Hibernate forum, but that remained unanswered as well.
Thanks
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Hmm. Can you tell us more? What does your mapping look like? What does your data model look like? What dialect are you using?
|
 |
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
Thanks for the reply.
I am using SQL server Dialect. I am setting the value using a setter.
p.setEmpApproverEmail(approverEmail.trim()); When I check the value after the values are stored in the database I find space appended to it.
In the database the feild is set to nvarchar(500).
|
 |
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
Hi ,
Is there anything wrong with the way i store it?
Thanks
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Sorry - slow hadn't noticed you'd updated this.
There is nothing in your code or in Hibernate that will do this. However SQL Server does have a frustrating mechanism to support ANSI padding (i.e. 'foo' == 'foo '), it will include a training space on the data inserted into an nvarchar field if you have ANSI_PADDING set to on. In older versions of SQL Server this defaulted to being on by default. Try updating your database properties to make sure ANSI_PADDING is off and see if it fixes it.
|
 |
Justin Howard
Ranch Hand
Joined: Feb 19, 2009
Posts: 162
|
|
Thanks for the reply Paul.
Will definitely try that !
Thanks
|
 |
 |
|
|
subject: Hibernate saves nvarchar values with a trailing space
|
|
|