【error】hibernate + mysql timestamp类型处理

参考:
Hibernate注解使用方法总结
MySQL timestamp NOT NULL插入NULL的问题
hibernate如何用annotation设置字段类型为时间戳的默认值为update

hibernate中实体类属性设置
@Column(name = “UP_DATE”,columnDefinition=”timestamp default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP”)

mysql配置explicit_defaults_for_timestamp
修改mysql安装目录下的bin/my.ini,将explicit_defaults_for_timestamp改为false,保存并重启mysql即可。

MySQL 5.6版本引入explicit_defaults_for_timestamp来控制对timestamp NULL值的处理。如果该参数不开启,即在my.cnf中explicit_defaults_for_timestamp=false,则对timestamp NOT NULL插入NULL值,不报错,无warning,插入后的值为当前时间。如果在my.cnf中explicit_defaults_for_timestamp=true(默认),那么插入该值的时候会报错提示该列can not be null。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章