I have an entity with a field to save the date when the entity was updated. I'm using the annotations below:
@Temporal(TemporalType.TIMESTAMP)
@UpdateTimestamp
@Column(name = "updated_at", nullable = true)
private Date updatedAt;
I want updatedAt
in null
as default value but I have as default value the same date when the entity was created.
In my @Service
class I save the entity like this:
visitorRepository.saveAndFlush(visitor)
There is a way to save my updatedAt in null as default value using @UpdateTimestamp?
createdAt
andupdatedAt
have the same value after entity creation.createdAt
have the@CreationTimestamp
annotation. – Reflective@UpdateTimestamp
usesGenerationTiming.ALWAYS
so a value is always generated (either INSERT or UPDATE). Not sure if will work, but perhaps try@Column(... insertable = false)
. – Interneexpected: 2021-06-18T12:20:36.492604+02:00[Europe/Berlin] (java.time.ZonedDateTime) but was : 2021-06-18T12:20:36.492092+02:00[Europe/Berlin] (java.time.ZonedDateTime)
– Goran