• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Hibernate saves nvarchar values with a trailing space

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

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

Thanks
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

Is there anything wrong with the way i store it?

Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Paul.

Will definitely try that !

Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic