[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-468?page=co...
]
Nikita D commented on HHH-468:
------------------------------
Perhaps the root problem is in org.hibernate.type.BooleanType, whose sqlType() method
returns java.sql.Types.BIT. Because of this, for a field whose type is a java
boolean/Boolean, the dialect class is actually asked to map a java.sql.Types.BIT to its
String column type. The MySQL dialect returns "bit" as the String for
java.sql.Types.BIT, but I think this actually makes sense since MySQL supports both BIT
and BOOLEAN (see
http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html).
java.sql.Types also defines both BIT and BOOLEAN.
From what I understand, here is how the mapping happens right now:
* The MySQL dialect registers the column type mapping registerColumnType(
Types.BIT, "bit" ). It doesn't register anything for
java.sql.Types.BOOLEAN.
* When generating the DDL, SchemaExport calls
Configuration.generateSchemaCreationScript(). For each column, the SQL type is retrieved
using Column.getSqlType().
* Column.getSqlType() gets the java.sql.Types type from the org.hibernate.type.Type of
the Column. This is where the org.hibernate.type.BooleanType returns java.sql.Types.BIT.
* The dialect's method getTypeName() is invoked with the java.sql.Types type in order
to get the string representation for the JDBC SQL type code.
So to me, it seems that the issue is the mapping from the java boolean/Boolean to the
java.sql.Types type, not in the dialect's mapping of the java.sql.Types type to its
String representation. If the MySQL dialect registered the type java.sql.Types.BOOLEAN,
and if org.hibernate.type.BooleanType returned java.sql.Types.BOOLEAN, booleans would be
mapped correctly. The problem is, I am not sure what the repercussions are of changing
org.hibernate.type.BooleanType.sqlType() or if there are particular reasons for it to be
implemented the way it is right now.
MysqlDialect incorrectly maps java.lang.Boolean to SQL BIT
----------------------------------------------------------
Key: HHH-468
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-468
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.0.3
Environment: Hibernate 3.0, MySQL.
Reporter: Mark Matthews
Assignee: Scott Marlow
I didn't track down how java.lang.Boolean gets mapped to Types.BIT in hibernate, but
you probably _don't_ want to map to "bit" like you do in MysqlDialect.
"bit", according to SQL99 (it's not in the core standard, and the type was
actually dropped for sql2k3) is a bitfield, not a boolean value. You can of course define
a bit(1), but it is technically more correct for java.lang.Boolean to map to a SQL BOOLEAN
for MySQL since we support a BOOLEAN and a BIT.
It looks like the JDBC-3.0 guys ignored what the standard said, because in reality
you'd want BIT to map to something like byte[], or java.util.BitSet if you were
tracking how the SQL standard defines BIT.
I'm guessing you probably want to map to "boolean", which the JDBC driver
will automagically convert for you, as it silently maps to TINYINT(1) on the server side.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira