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