Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Field with @CreationTimestamp annotation is null while save on repository

Tags:

(1) Why is the "@CreationTimestamp" field updated to null for a "save" called on the repository with a null value for that field? I expect that a field annotated with "@CreationTimestamp" is never updated and maintained only once at the time of creation. But it does not work that way in my current project.

(2) I had to include @Column(updatable =false) (in addition to @CreationTimestamp annotation). Why is this necessary?

like image 403
Jothi Avatar asked Jul 06 '16 14:07

Jothi


1 Answers

It's 2020, hibernate-core-5.3.12, and still need to set updatable to false.

@CreationTimestamp       @Column(updatable = false) private LocalDateTime createdDate; 

Update

I believe there will be no fix for this because this CreationTimestamp is from native hibernate package (org.hibernate.annotations), and I believe the efforts will be on the jpa abstraction (org.springframework.data.annotation.CreatedBy)

like image 95
Guilherme Alencar Avatar answered Sep 21 '22 18:09

Guilherme Alencar