-->
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.  [ 4 posts ] 
Author Message
 Post subject: truncating data to fit table fields
PostPosted: Fri Jul 25, 2008 1:58 pm 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
Hi,

I'm using Hibernate to save data into a database table from a message driven bean that's acting as a log data collector service for the entire organization. Any application can post log data to the queue and this data can be arbitrary. If the data is larger than the the table field, right now I'm getting a "Data truncation: Data too long for column" exception. Really, I don't care if the data is too large, I just want to be able to save truncating data if necessary. I would also like to avoid hardcoding field lengths into the code. Is there any way I can have Hibernate automatically trim the data to the appropriate field lengths (since this data is available in the JDBC meta data which Hibernate has access to)?

Thanks
Dmitry


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 27, 2008 11:12 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, if it's a POJO that has a setter being called, you could just do a trim of the data in the setter of the POJO. But you did say you didn't want to do it programatically? A trim is pretty easy - it might be the best way.

What about changing the datatype in the system? CLOB or BLOB or something? Might that work?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 27, 2008 11:18 am 
Regular
Regular

Joined: Wed Sep 10, 2003 2:26 pm
Posts: 56
Location: San Diego, CA
Cameron McKenzie wrote:
Well, if it's a POJO that has a setter being called, you could just do a trim of the data in the setter of the POJO. But you did say you didn't want to do it programatically?


it's not the question or hard or easy. I don't want the definition of a field's length to live in two places: in the code and in the database. Then if it changes, it'll need to be changed twice (remembered to be changed twice). Since the value is already in the database and I want to reuse it.

Cameron McKenzie wrote:
What about changing the datatype in the system? CLOB or BLOB or something? Might that work?


Not for data is normally small, like event category name.


Top
 Profile  
 
 Post subject: Re: truncating data to fit table fields
PostPosted: Tue Sep 14, 2010 10:15 am 
Newbie

Joined: Fri Jan 12, 2007 12:24 pm
Posts: 5
Location: Geneva, Switzerland
I have the same problem.

I don't want the definition of a field's length to live in two places: in the code and in the database.

I would like to use the database definition to do the trim(). Is it possible to retrieve the field definition ?

dberansky have you found a solution ?

Regards

_________________
Regards

Soraya


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