“Found: bit, expected: boolean” after Hibernate 4 upgrade

前端 未结 5 1844
无人及你
无人及你 2020-12-08 14:03

I\'m trying to upgrade from Hibernate 3.6.5 to 4.0 (and from Spring 3.0.5 to 3.1 which is required for Hibernate 4 support).

Now, with both MySQL and HSQL, I\'m runn

相关标签:
5条回答
  • 2020-12-08 14:22

    I was able to solve this issue by adding transformedBitIsBoolean=true to my MySQL connection string. See here: https://hibernate.atlassian.net/browse/HHH-6935

    0 讨论(0)
  • 2020-12-08 14:32

    I had the same problem and I extended the Dialect to take into account the fact that mysql treats boolean as an alias of bit.

    public class Mysql5BitBooleanDialect extends MySQL5Dialect{     
        public Mysql5BitBooleanDialect() {
            super();
            registerColumnType( java.sql.Types.BOOLEAN, "bit" );        
        }       
    }
    

    I don't use longer bit() fields (to represent for example byte[]) so this might break that.

    0 讨论(0)
  • 2020-12-08 14:43

    I worked this out by adding columnDefinition = "BIT" to the @Column line.

    @Basic
    @Column(name = "B", columnDefinition = "BIT", length = 1)
    public boolean isB() {
        return b;
    }
    

    Its defined as a 'BIT(1)' in the DB as well. Also worked with TINYINT. This is the easiest solution I've found since the change is super-minor and no need to touch the DB.

    Using: MySQL Server 5.5.13, Hibernate 4.1.1, JDK 1.6

    0 讨论(0)
  • 2020-12-08 14:43

    This has been answered in a similar question here :

    Hibernate JPA, MySQL and TinyInt(1) for Boolean instead of bit or char

    Your problem could be a bit more complicated as you use HSQL DB at the same time, but you can take a look and try it anyway !

    0 讨论(0)
  • 2020-12-08 14:45

    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 );
    }
    
    0 讨论(0)
提交回复
热议问题