ON UPDATE CURRENT_TIMESTAMP and JPA

前端 未结 2 1820
轻奢々
轻奢々 2021-01-02 19:26

I have an entity with fields

@Temporal(TemporalType.TIMESTAMP)
@Column(name = \"edit_timestamp\", 
        columnDefinition=\"TIMESTAMP DEFAULT CURRENT_TIMES         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 20:20

    You need to change the column annotation to include updatable = false. This will cause the edit_timestamp column to not show up in the update SQL, so the JPA provider won't include the current value of the field which is what is causing it to override the default.

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "edit_timestamp", 
            updatable = false,
            columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
    private Date editTimestamp;
    

提交回复
热议问题