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;
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;
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.
A good tutorial about Spring Data JPA : Auditing