Alex Rivera | Logout

"Found: bit, expected: boolean" after Hibernate 4 upgrade

Asked 2011-12-29T12:37:23.360
34

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 running into this problem with persistent boolean fields:

Caused by: org.hibernate.HibernateException: 
Wrong column type in PUBLIC.PUBLIC.EVENT for column Checked. Found: bit, expected: boolean
    at org.hibernate.mapping.Table.validateColumns(Table.java:282)
    at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1268)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:155)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:453)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:184)
    at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:314)

JPA @Entity and @Column annotations are used in domain objects, and the problematic fields look like this:

@Column(name = "Checked")
private boolean checked;

HSQL schema:

Checked bit default 0 not null,

MySQL schema:

`Checked` tinyint(1) NOT NULL default '0',

What is the most straightforward way to solve this while sticking with Hibernate 4? Should I change the database schema, Hibernate configs, or domain class annotations?

I have no idea if the code and configuration was fully "correct" before, but at least it worked fine with Hibernate 3.

Edit
Report

1 Answer

-1

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 );
}
answered 2012-01-04T14:33:20.010

Your Answer