EntityDate
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
@Getter
public abstract class EntityDate {
@CreatedDate
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt;
@LastModifiedDate
@Column(nullable = false)
private LocalDateTime modifiedAt;
ServerApplication.java
@SpringBootApplication
@EnableJpaAuditing
public class ServerApplication{
public abstract class EntityDate {
@CreatedDate
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt;
@LastModifiedDate
@Column(nullable = false)
private LocalDateTime modifiedAt;
public void setModifiedAt(LocalDateTime modifiedAt) {
this.modifiedAt = modifiedAt;
}
}
당연히, set Modified at을 통해 set 시켜주므로 modifiedAt은 createdAt 아이와 달리 updatable=true 여야 한다, 이것은 디폴트 값이라서 그냥 저렇게 냅두면 됩니다.
this.setModifiedAt(LocalDateTime.now());