-->
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: java String longer than 255 chars converts to varchar(255)
PostPosted: Tue May 08, 2007 11:12 am 
Newbie

Joined: Tue May 08, 2007 10:55 am
Posts: 5
When persisting an EJB3 entity bean "PageResult" containing a variable of type String called "pageText", the most recent version of Hibernate first creates the table "PageResult" with the column "pageText" of sql data type VARCHAR(255).

Hibernate then tries to persist a "PageResult" EJB containing a "pageText" of _more_ than 255 characters, throwing the error:

Code:
ERROR [org.hibernate.util.JDBCExceptionReporter] Data truncation: Data too long for column 'pageText' at row 1



The database used is MySql 5.0 .
The JDBC driver used is mysql-connector-java-5.0.5-bin.jar .


Any ideas on how to store a String greater than 255 chars?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 12:02 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
You can specify the length you want the column to have.

Look at this

http://www.hibernate.org/hib_docs/annot ... rty-column

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 8:08 am 
Newbie

Joined: Tue May 08, 2007 10:55 am
Posts: 5
I already tried adding the annotation @Column(lenght=5000), but a MySql column VARCHAR(255) was created.

Today I added the annotation @Column(columnDefinition="TEXT"), which indeed created the MySql pageText column with the data type TEXT. However, even with the data type TEXT, I still get the Hibernate exception

Code:
WARN [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: 22001
09 mei 13:57 ERROR [org.hibernate.util.JDBCExceptionReporter] Data truncation: Data too long for column 'pageText' at row 1


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 10:48 am 
Newbie

Joined: Tue May 08, 2007 10:55 am
Posts: 5
Fixed the problem myself. Added the annotation @Column(columnDefinition="LONGTEXT").


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.