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; } }