-->
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.  [ 12 posts ] 
Author Message
 Post subject: String can only have 255 characters
PostPosted: Sat Jul 28, 2007 3:11 pm 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Hi

I used the search for this issue but I couldn't find anything that helped. My problem is that in my application the user can add comments for some objects and these can be pretty long.

I am getting a DataException saying that it was not possible to split up the string.

What can I do to fix this?
Thx


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 3:14 pm 
Newbie

Joined: Sun Oct 01, 2006 6:33 am
Posts: 8
The column in the underlying table should be set to text / blob. varchar can store up to 255 symbols. That is - the problem might not be in Hibernate, but in the underlying database?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 3:23 pm 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Thanks for your quick reply.

I am using Derby which supports blobs as far as I know. How can I tell Hibernate to use text /blob?

-Marc


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 4:05 pm 
Newbie

Joined: Sun Oct 01, 2006 6:33 am
Posts: 8
<property
name="comment"
type="java.lang.String"
update="true"
insert="true"
column="comment"
/>

And if the underlying field is blob, there should be no problem.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 4:21 pm 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Thanks, but I am creating my Database from Hibernate. Is this possible or do I have to create the Database with DDL?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 4:44 pm 
Newbie

Joined: Sun Oct 01, 2006 6:33 am
Posts: 8
I do not know if it is possible. I would personally recommend creating the database with DDL, or using some database browser.


Top
 Profile  
 
 Post subject: Why not > 255?
PostPosted: Tue Jul 31, 2007 8:36 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
Have you specified a length for the property?
255 is only the default length.

But blobs would be better for these kind of fields.

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 8:48 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Specify the property type as blob rather than string. This way hibernate will create a blob field in the database for you.
Code:
<property
name="comment"
type="blob"
/>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 8:53 am 
Newbie

Joined: Mon Jul 30, 2007 10:12 pm
Posts: 13
Location: Orust/Sweden
Use text for this. If it's pure text message

Code:
<property name="comment" type="text" />


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 31, 2007 8:58 am 
Newbie

Joined: Sun Apr 09, 2006 8:38 am
Posts: 14
Usually, hibernate chooses a default length for the column.
You can specify the length explicitly, i.e.
<property type="java.lang.String" name="property1">
<column name="property1_col" length="200" />
</property>

Still, normally if the length you specified exceeded the DB's max column length for the (varchar) type, usually you'll recieve the maximal length allowed.

And of course you can specify that this property is mapped as clob/text (depending on your DB provider...)

Hope this helps.

A.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 5:54 pm 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Thanks for the replies.

type="text" seems not to work, I am still getting the same error message saying "can't split up". So I tried type="binary" and now I am getting the message "cannot cast String to [B"

I can't use this length-property since I don't know exactly how long the text will be in production. I guess I have to write it with a DDL :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 06, 2007 3:36 pm 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Code:
<property name="comment">
   <column name="COMMENT" sql-type="clob"/>
</property>


This did the trick


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