-->
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: upgrade MySQL 5.0.18, boolean type data too long
PostPosted: Mon Feb 06, 2006 1:28 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
MySQL 4.1 uses TINYINT for Boolean type, but MySQL 5.0 use Bit(1). After upgrading to MySQL 5.0 and all mapping tables have been re-created.

I got

Data too long for column "read" that is a boolean type.

when inserting a row.

How to solve this problem? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 06, 2006 10:24 am 
Newbie

Joined: Mon Jan 17, 2005 1:09 pm
Posts: 19
I'm having the same problem, did you find an solution?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 12:44 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Heox wrote:
I'm having the same problem, did you find an solution?


No. back to MySQL 4.1


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 8:46 am 
Newbie

Joined: Mon Jan 23, 2006 1:11 pm
Posts: 15
Location: Leuven, Belgium
The easiest, and most reliable method, would be to do the update yourself...

First you add an extra bit column
Then you update the values so that:
update mytable set bitvalue=1 where tinyintcolumn = 1
update mytable set bitvalue=0 where tinyintcolumn = 0
update mytable set bitvalue=null where tinyintcolumn is null
Now you delete the tinyintcolumn
Rename bitcolumn to tinyintcolumn

Done.

_________________
Don't applaud, throw money (paypal to timvw@users.sourceforge.net) - http://www.timvw.be


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 4:02 am 
Newbie

Joined: Fri Feb 10, 2006 2:57 am
Posts: 14
take a look at http://opensource2.atlassian.com/projec ... se/HHH-468 for a discussion of the subject.

The thread is geared towards those using hbm files, so if you are using annotations, you can use the @Column annotation with the
"columnDefinition" attribute set to "BOOLEAN" to get around this. The newer MySQL JDBC driver then silently converts this to tinyint(1) for you and you are back to the behavior as under MySQL 4.x

For example:

Code:
    @Column(columnDefinition="BOOLEAN")
    public java.lang.Boolean getDisabled() {
        return disabled;
    }


I've tested this with MySQL ConnectorJ 3.1.12 and MySQL 5.0.18 and my DDL generates correctly (i.e. tinyint(1) is back)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 4:13 am 
Newbie

Joined: Fri Feb 10, 2006 2:57 am
Posts: 14
BTW, maybe someone on the Hibernate team could add an example like this to the documentation and/or unit test code?

The unit tests that come with annotations do not have an example of @Column using the "columnDefinition" attribute and the documentation just says "(6) columnDefinition (optional): override the sql DDL fragment for this particular column (non portable)" which is not exactly clear on what you should do.

Even better, a cross-reference document for moving from hbm to annotations would be really slick, something like:

Defining the database type:
HBM: uses the "sql-type" attribute
Annotations: uses the "columnDefinition" attribute of @Column

Defining the hibernate type:
HBM: uses the "type" attribute
Annotations: uses the "type" attribute of @Type


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 7:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There are examples in the unit test suite

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 1:45 pm 
Newbie

Joined: Fri Feb 10, 2006 2:57 am
Posts: 14
I see now... a file search using Win32's built in search did not find any mention of "columnDefinition" but when I used grep in cygwin, I found some examples:

Code:
$ grep -r columnDefinition .
./org/hibernate/test/annotations/entity/Bid.java:       //@Column(columnDefinition = "VARCHAR(10)")
./org/hibernate/test/annotations/onetomany/PoliticalParty.java: @Column(columnDefinition = "VARCHAR(60)")
./org/hibernate/test/annotations/onetomany/Politician.java:     @Column(columnDefinition = "VARCHAR(30)")
./org/hibernate/test/annotations/Sky.java:      @Column(unique=true, columnDefinition="varchar(250)")


Thanks! BTW, great job on the annotations package - they are working out very well for us.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 12, 2006 10:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
thanks :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 9:06 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
3point wrote:
take a look at http://opensource2.atlassian.com/projec ... se/HHH-468 for a discussion of the subject.

The thread is geared towards those using hbm files, so if you are using annotations, you can use the @Column annotation with the
"columnDefinition" attribute set to "BOOLEAN" to get around this. The newer MySQL JDBC driver then silently converts this to tinyint(1) for you and you are back to the behavior as under MySQL 4.x

For example:

Code:
    @Column(columnDefinition="BOOLEAN")
    public java.lang.Boolean getDisabled() {
        return disabled;
    }


I've tested this with MySQL ConnectorJ 3.1.12 and MySQL 5.0.18 and my DDL generates correctly (i.e. tinyint(1) is back)


Bit(1) is better than TINYINT for boolean type. The table schema is generated using Bit(1). I do not understand why it complains too long when inserting records.

I have many entities, and lots of Boolean type columns. Using columnDefinition is not a good idea because it is not portable.
Hibernate should have a nicer way to solve this. Has Hibernate tested on MySQL 5.0.18?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 7:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes I test on MySQL 5
This is not Hibernate's responsibility if MySQL decide to break their client's applications.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 8:43 pm 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Why is it MySql problem?
The mapping is done by Hibernate, and SQL dialect is generated by Hibernate.

After installed MySQL 5, I removed all tables from database, and recompile web application, and re-deploy it. Everything is fine until an entity with Boolean properties is persisted.


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.