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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…