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.  [ 3 posts ] 
Author Message
 Post subject: character can be empty in mysql
PostPosted: Thu Nov 23, 2006 7:59 am 
Newbie

Joined: Wed Apr 26, 2006 11:39 am
Posts: 8
Location: bracknell, UK
A bug in Hibernate core's org.hibernate.type.CharacterType, in public Object get(ResultSet rs, String name), there's a mistaken assumption that either the value is null or it always has a str.charAt(0).

In MySQL, a char(1) can contain an empty string.

This results in an error like
Code:
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.lang.String.charAt(String.java:558)
        at org.hibernate.type.CharacterType.get(CharacterType.java:29)

This is still present in the latest version.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 8:33 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
mmm, I'm not sure, but it seems to be a MySQL problem instead of hibernate problem...

well when something is char(1) it must contain a single character...

even in MySQL an empty VARCHAR differs by null...

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 23, 2007 1:08 pm 
Newbie

Joined: Wed Aug 10, 2005 12:36 pm
Posts: 1
Hello,
we have the same problem here at a clients database.
MySQL Version: 5.0.27 Standard Community Edition

I have searched the forum. It seems that this is a problem for others too, but I couldnt find a solution so far.

Our case is the following:
We have an Order table, and there is a SQL CHAR(1) field.
But in some Orders there is an empty string "" in this column. The field is defined as


Code:
`myField` char(1) collate latin1_general_ci NOT NULL default 'N',


We use Hibernate with Annotations and the mapping of this field looks like:

Code:
@Column(name = "myField", unique = false, nullable = false, insertable = true, updatable = true, length = 1)
   public char getMyField() {
      return this.myField;
   }


Is there anything we can do from withhin Hibernate to prevent this? Either a change to the annotation.
I don;t know if we can manage to change anything at the database level.

Thanks
Christoph


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