지나공 : 지식을 나누는 공간

스프링 부트와 AWS로 혼자 구현하는 웹서비스 정리 - Chapter 03 JPA Auditing, @MappedSuperclass, @EntityListeners, @createdDate 등 본문

Tech/Spring Boot

스프링 부트와 AWS로 혼자 구현하는 웹서비스 정리 - Chapter 03 JPA Auditing, @MappedSuperclass, @EntityListeners, @createdDate 등

해리리_ 2021. 1. 11. 17:48

 

 

03장 마지막 JPA Auditing으로 생성시간/수정시간 자동화하기

 

BaseTimeEntity

 

 

BaseTimeEntity는 abstract 클래스로, Entity들의 생성시간과 수정시간을 자동으로 관리하는 역할을 한다.

 

@MappedSuperclass

JPA Entity 클래스들이 BaseTimeEntity를 상속할 경우 그 필드들인 createdDate, modifiedDate를 컬럼으로 인식하도록 한다.

 

 

@EntityListeners(AuditingEntityListener.class)

BaseTimeEntity 클래스에 Auditing 기능을 포함시킨다.

 

 

 

@createdDate

Entity가 생성되어 저장될 때 시간이 자동저장된다.

 

 

 

@LastModifiedDate

조회한 Entity의 값을 변경할 때 시간이 자동저장된다.

 

728x90
Comments