Reputation: 47
I have created an entity and I want to give createdDate
variable, the CURRENT_TIMESTAMP
default value, how can I do that?
@Column(name = "created_date")
private LocalDateTime createdDate;
Upvotes: 4
Views: 588
Reputation: 18430
You can use @CreatedDate
with Spring Data JPA provided AuditingEntityListener
@EntityListeners(AuditingEntityListener.class)
class Entity {
...
@CreatedDate
@Column(name = "created_date")
private LocalDateTime createdDate;
...
}
Then use @EnableJpaAuditing
on your application main class to enable the Spring Data JPA Auditing features for the application.
Upvotes: 1