Hibernate Books

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Nhibernate unable to save value in varchar(30) column
PostPosted: Tue Apr 08, 2008 11:38 pm 
Newbie

Joined: Tue Apr 08, 2008 11:29 pm
Posts: 3
Hi,
I have a property called Name (string type) which maps to name column in database table. This column is varchar(30). When I map the column in the mappping file, I specify the length attribute for the property as 30. I assume that hiberate will automatically trim name property to 30 characters when saving the value to the database.

However, when the application specifies a value of more than 30 characters to name property and tries to save it in the database, nhibernate gives an error saying "string or binary data would be truncated". It does not seems to truncate the name property to 30 characters automatically and save in the database but rather throws the above error.

Please let me know if there is any way to configure nhibernate so that it can automatically truncate a property before saving it in the database if the length of the property is more than what is specified in the mapping file.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 07, 2008 2:10 pm 
Newbie

Joined: Thu Jun 28, 2007 5:02 pm
Posts: 12
Yeah. This used to work the way you're describing. It used to sub-string the value to the specified length when generating/performing the insert/update query.

I ran into this problem today too.

The real question is... Is the nHibernate roadmap changing the behavior of truncation? (i.e. do we have to manage it in the client code before it hits the underlying database going forward?)

Or is this a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 08, 2008 2:33 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I ran into the same problem a few weeks ago. Specifiying the sql-type, too, solved the problem for me:

Code:
sql-type="varchar(30)" length="30"

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 12:14 pm 
Newbie

Joined: Thu Jun 28, 2007 5:02 pm
Posts: 12
Hey Wolli... What version of NHibernate are you running?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 11, 2008 12:28 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
1.2.1 GA

_________________
--Wolfgang


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