Why @UpdateTimestamp is setting a value by default on entity creation?

Viewed 519

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?

1 Answers

As Andrew S suggested in a comment, a combination of @UpdateTimestamp and @Column(... insertable = false) did the trick form me.

Related