【发布时间】:2012-01-29 21:03:49
【问题描述】:
我正在尝试从 Hibernate 3.6.5 升级到 4.0(以及从 Spring 3.0.5 升级到 3.1,这是支持 Hibernate 4 所必需的)。
现在,对于 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 架构:
`Checked` tinyint(1) NOT NULL default '0',
在坚持使用 Hibernate 4 时最直接的解决方法是什么?我应该更改数据库架构、Hibernate 配置还是域类注释?
我不知道之前的代码和配置是否完全“正确”,但至少它在 Hibernate 3 中运行良好。
【问题讨论】:
-
使用 HSQL,将模式文件中的“bit”更改为“boolean”似乎会有所帮助(即,我遇到了另一个 Hibernate 4 问题)。不过这有点奇怪,因为HSQL documentation 给人的印象是 BOOLEAN 和 BIT 是等价的。
标签: java mysql hibernate hsqldb hibernate-4.x