[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-468) MysqlDialect incorrectly maps java.lang.Boolean to SQL BIT

Corey Lohman (JIRA) noreply at atlassian.com
Wed Jun 25 01:55:19 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-468?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30506 ] 

Corey Lohman commented on HHH-468:
----------------------------------

To get booleans working without custom code this alias may be useful (works for MySQL -> HBM -> Java tooling):

1) represent booleans with TINYINT(1)

2) Add to cfg tinyInt1isBit=true & transformedBitIsBoolean=true:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.tinyInt1isBit">true</property>
<property name="hibernate.connection.transformedBitIsBoolean">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>

3) if running hbm2hbmxml, hbm2cfgxml, hbm2java use jdbcconfiguration, not configuration

One version set this worked on: JDK 1.5.0_09, Connect/J 5.1.6, Hibernate 3.2, Tools 3.2.2b1


> MysqlDialect incorrectly maps java.lang.Boolean to SQL BIT
> ----------------------------------------------------------
>
>                 Key: HHH-468
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-468
>             Project: Hibernate3
>          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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list