“发现:位,预期:布尔值”在 Hibernate 4 升级后
2022-09-01 08:11:32
我正在尝试从Hibernate 3.6.5升级到4.0(以及从Spring 3.0.5升级到Hibernate 4支持所需的3.1)。
现在,对于MySQL和HSQL,我在持久布尔字段方面遇到了这个问题:
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
和@Column
注释用于域对象中,有问题的字段如下所示:
@Column(name = "Checked")
private boolean checked;
HSQL 模式:
Checked bit default 0 not null,
MySQL schema:
`Checked` tinyint(1) NOT NULL default '0',
在坚持使用Hibernate 4的同时解决这个问题的最直接方法是什么?我应该更改数据库架构、休眠配置还是域类注释?
我不知道之前的代码和配置是否完全“正确”,但至少它在Hibernate 3中工作正常。