I am starting with a project and I want to start inserting the application insert some tables, I would do it in the BD but I have attributes "created_At"
and "update_At"
:
package com.example.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(
value={"cratedAt","updateAt"},
allowGetters=true
)
public abstract class AuditModel {
@Temporal(TemporalType.TIMESTAMP)
@Column(name="created_at",nullable=false,updatable=false)
@CreatedDate()
private Date createdAt;
@Temporal(TemporalType.TIMESTAMP)
@Column(name="update_at",nullable=false)
@LastModifiedDate
private Date updateAt;
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getUpdateAt() {
return updateAt;
}
public void setUpdateAt(Date updateAt) {
this.updateAt = updateAt;
}
}
which I inherit from all my entities. spring boot handles the insertions to these attributes, some way to perform the pre-insertion?