【error】hibernate + mysql timestamp类型处理

    xiaoxiao2021-03-25  70

    参考: 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。

    转载请注明原文地址: https://ju.6miu.com/read-15530.html

    最新回复(0)