//BaseTimeEntity.java
package com.eunyeong.book.springboot.domain;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;
@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseTimeEntity {
@CreatedDate
private LocalDateTime createdDate;
@LastModifiedDate
private LocalDateTime modifiedDate;
}
● @MappedSuperclass
JPA Entity 클래스들이 BaseTimeEmtity를 상속할 경우 createdDate, modifiedDate도 칼럼으로 인식하도록 합니다.
● @EntityListeners(AuditingEntityListener.class)
BaseTimeEntity 클래스에 Auditing 기능을 포함시킵니다.
● @CreatedDate
Entity가 생성되어 저장될 때 시간이 자동 저장됩니다.
● @LastModifiedDate
Entity의 값을 변경할 때 시간이 자동 저장됩니다.
'Springboot' 카테고리의 다른 글
[Springboot] mysql 연결 과정과 에러 정리 (1) | 2022.02.26 |
---|---|
[Springboot-error] @Transactional(readOnly = true) 옵션 못 찾음 (0) | 2022.01.28 |
[Springboot-error] 테스트코드 에러 (1) | 2022.01.25 |
[Springboot] org.junit.ComparisonFailure: 401 에러 (1) | 2022.01.21 |
[Springboot] 테스트코드 작성 (0) | 2022.01.19 |