Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate saves nvarchar values with a trailing space

 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

If I have posted the question in the wrong forum please let me know.

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing to do with Hibernate I think. What makes you think it is Hiberate that is causing the problem?
 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Is there anything wrong with the way i store it?

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Paul.

Will definitely try that !

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic