我的实体中有一个布尔属性。以下是我的注解:
@Column(name = "IS_ACTIVE", nullable = false, columnDefinition="BIT DEFAULT 1", length = 1)
public Boolean getActive() {
return isActive;
}
但是columnDefinition="BIT DEFAULT 1"
并不完美地工作。以下是生成表的结果的SQL代码:
IS_ACTIVE BIT(1) NOT NULL,
我做错了什么?
当我尝试将这个类的实例保存到数据库中时,就会出现异常:
`com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'IS_ACTIVE' cannot be null`
如果我删除
nullable = false
属性:@Column(name = "IS_ACTIVE", columnDefinition="BIT DEFAULT 1", length = 1)
public Boolean getActive() {
return isActive;
}
我希望能够保存创建的对象。但是,默认值未设置,因此在数据库中该字段的值为NULL。
请问有什么建议吗?如果重要的话,我使用的是MySQL Server 5.1版本。非常感谢您的帮助。提前致谢!
hibernate.hbm2ddl.auto
的 create-drop 功能。现在我的数据库中有一个IS_ACTIVE TINYINT(1) NOT NULL DEFAULT '0',
字段。非常好!但是为什么默认值是 NULL 呢?你有什么想法吗? - Philiph Brunocom.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'IS_ACTIVE' cannot be null
。 - Philiph Bruno