hibernate sets default value of timestamp and automatic update of update time

  1. Execute the following sql in the data table that needs the two fields of creation time and update time
   alter table user add create_time timestamp not null default current_timestamp comment '创建时间';
   alter table user add update_time timestamp not null default current_timestamp on update current_timestamp comment '修改时间';
  1. The corresponding entity adds these two attributes and marks the corresponding annotation. In the test, it was found that if the first step is not performed, the tables and fields automatically created by hibernate cannot be automatically filled with the creation time and update time, that is to say, these two properties are empty when inserting data.
    @Temporal(TemporalType.TIMESTAMP)  
    @Column(name="create_time",  nullable=true, updatable = false)  
    @Generated(GenerationTime.INSERT)
	private Date createTime;
    @Temporal(TemporalType.TIMESTAMP)  
    @Column(name="update_time",  nullable=true)  
    @Generated(GenerationTime.ALWAYS)
	private Date updateTime;
    // 省略其它属性和get、set的方法

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325315513&siteId=291194637