From d1bf1dd4771ba0f9ee3b9d90de9e729c7936c780 Mon Sep 17 00:00:00 2001 From: sohot8653 Date: Tue, 12 Aug 2025 15:39:35 +0900 Subject: [PATCH] =?UTF-8?q?[=ED=9A=8C=EC=9B=90=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EB=B0=8F=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0]=20-=20Member=20=EC=97=94=ED=8B=B0=ED=8B=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20onPostPersist=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0,=20MemberServiceImpl=EC=97=90=EC=84=9C=20OID?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80,=20BaseEntity=EC=97=90?= =?UTF-8?q?=EC=84=9C=20OID=20=EC=B4=88=EA=B8=B0=ED=99=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/member/entity/Member.java | 10 ---------- .../user/member/service/MemberServiceImpl.java | 6 ++++++ .../bio/bio_backend/global/entity/BaseEntity.java | 14 ++++---------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/bio/bio_backend/domain/user/member/entity/Member.java b/src/main/java/com/bio/bio_backend/domain/user/member/entity/Member.java index 29e4367..2421ef6 100644 --- a/src/main/java/com/bio/bio_backend/domain/user/member/entity/Member.java +++ b/src/main/java/com/bio/bio_backend/domain/user/member/entity/Member.java @@ -44,14 +44,4 @@ public class Member extends BaseEntity { @Column(name = "last_login_at") private LocalDateTime lastLoginAt; - /** - * 엔티티 저장 후 실행되는 메서드 - * createdOid와 updatedOid를 자기 자신의 oid로 설정 - */ - @PostPersist - protected void onPostPersist() { - if (this.getCreatedOid() == null) { - this.setCreatedOid(this.getOid()); - } - } } \ No newline at end of file diff --git a/src/main/java/com/bio/bio_backend/domain/user/member/service/MemberServiceImpl.java b/src/main/java/com/bio/bio_backend/domain/user/member/service/MemberServiceImpl.java index 40b6451..65ed12c 100644 --- a/src/main/java/com/bio/bio_backend/domain/user/member/service/MemberServiceImpl.java +++ b/src/main/java/com/bio/bio_backend/domain/user/member/service/MemberServiceImpl.java @@ -17,6 +17,8 @@ import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; +import static com.bio.bio_backend.global.utils.OidUtil.generateOid; + @Service @RequiredArgsConstructor @Slf4j @@ -52,6 +54,10 @@ public class MemberServiceImpl implements MemberService { .password(bCryptPasswordEncoder.encode(memberDTO.getPassword())) .role(MemberRole.getDefault()) .build(); + + Long oid = generateOid(); + member.setOid(oid); + member.setCreatedOid(oid); Member savedMember = memberRepository.save(member); diff --git a/src/main/java/com/bio/bio_backend/global/entity/BaseEntity.java b/src/main/java/com/bio/bio_backend/global/entity/BaseEntity.java index 86ed367..f8652c3 100644 --- a/src/main/java/com/bio/bio_backend/global/entity/BaseEntity.java +++ b/src/main/java/com/bio/bio_backend/global/entity/BaseEntity.java @@ -6,10 +6,11 @@ import lombok.Setter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import com.bio.bio_backend.global.utils.OidUtil; import java.time.LocalDateTime; +import static com.bio.bio_backend.global.utils.OidUtil.generateOid; + /** * 모든 엔티티가 상속받는 기본 엔티티 클래스 * 공통 필드들을 정의하고 JPA Auditing을 지원합니다. @@ -40,14 +41,7 @@ public abstract class BaseEntity { @PrePersist protected void onCreate() { - LocalDateTime now = LocalDateTime.now(); - this.oid = OidUtil.generateOid(); - this.createdAt = now; - this.updatedAt = now; - } - - @PreUpdate - protected void onUpdate() { - this.updatedAt = LocalDateTime.now(); + if(this.oid == null) this.oid = generateOid(); + if(this.createdOid != null && this.updatedOid == null) this.updatedOid = this.createdOid; } }