HibernateException in mysql Found: bit, expected: boolean
Description
Attachments
- 04 Jan 2012, 05:13 PM
caused by
Activity

Brett Meyer March 7, 2014 at 10:08 PM
Bulk closing tickets resolved in released versions

Himavanth Rachamsetty September 24, 2013 at 9:38 AMEdited
I have a feeling that this won't fix the issue completely because the sql type descriptor for BooleanType is still BooleanTypeDescriptor.
And that will fail when trying to insert null value. It wouldn't fail if it was set to BitTypeDescriptor.
I am having that problem with sqlserver2000 right now and if i override Types.Boolean with BitTypeDescriptor in getSqlTypeDescriptorOverride(), it started working.
More detailed explanation at https://forum.hibernate.org/viewtopic.php?f=1&t=1025583&p=2472090#p2472090

Brett Meyer July 1, 2013 at 9:22 PM
The original discussion on made the point that the boolean type was technically "more correct" for JDBC. However, since boolean is just a synonym for tinyint in MySQL, and the JDBC ColumnMetadata for a "boolean" MySQL column is of type BIT, I'm switching MySQLDialect back to the bit column type.

Mike Huniewicz June 26, 2013 at 9:43 AM
It could be MySQL after all. Here's what I have found out:
There is a way to overcome this without using columnDefinition in the code - using a MySQL connection parameter.
You'd have to set transformedBitIsBoolean to true on the connection string. Because MySQL doesn't have a boolean datatype, Hibernate complains. Using the transformedBitIsBoolean parameter we can make the driver treat transformed BIT fields as Boolean. Transformed means however, it cannot actually be a BIT field, it has to be another field type silently transformed into BIT. That other field type is TINYINT(1).
So in order to get rid of column definitions we'd have to not only use the connection parameter, but also convert all the BIT fields into TINYINT(1), and the tinyInt1isBit flag has to be set to true (which it is by default).
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html

Mike Huniewicz April 3, 2013 at 4:09 PM
If I let Hibernate generate my DB schema (hbm2ddl.auto == create-drop), it creates my boolean fields as tinyint(1). It works. But if I then change hbm2ddl.auto to validate - it fails with the aforementioned error.
In other words, Hibernate created the column as tinyint(1), and now it complains about it not being boolean. Seems like a bug?
Details
Assignee
Brett MeyerBrett MeyerReporter
Orasio SpielerOrasio SpielerLabels
Components
Fix versions
Affects versions
Priority
Major
Details
Details
Assignee

Reporter

Found the problem i also got org.hibernate.HibernateException: Wrong column type ... Found: bit, expected: boolean
on BooleanType in hibernate 4 they changed the Ctor to
public BooleanType() {
this( org.hibernate.type.descriptor.sql.BooleanTypeDescriptor.INSTANCE, BooleanTypeDescriptor.INSTANCE );
}
instead of old versions
public BooleanType() {
this( BitTypeDescriptor.INSTANCE, BooleanTypeDescriptor.INSTANCE );
}
spieler.orasio@gmail.com