[회원 엔티티 및 서비스 개선] - Member 엔티티에서 onPostPersist 메서드 제거, MemberServiceImpl에서 OID 생성 및 설정 로직 추가, BaseEntity에서 OID 초기화 로직 수정

This commit is contained in:
2025-08-12 15:39:35 +09:00
parent c50e8d835b
commit d1bf1dd477
3 changed files with 10 additions and 20 deletions

View File

@@ -44,14 +44,4 @@ public class Member extends BaseEntity {
@Column(name = "last_login_at") @Column(name = "last_login_at")
private LocalDateTime lastLoginAt; private LocalDateTime lastLoginAt;
/**
* 엔티티 저장 후 실행되는 메서드
* createdOid와 updatedOid를 자기 자신의 oid로 설정
*/
@PostPersist
protected void onPostPersist() {
if (this.getCreatedOid() == null) {
this.setCreatedOid(this.getOid());
}
}
} }

View File

@@ -17,6 +17,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static com.bio.bio_backend.global.utils.OidUtil.generateOid;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j @Slf4j
@@ -52,6 +54,10 @@ public class MemberServiceImpl implements MemberService {
.password(bCryptPasswordEncoder.encode(memberDTO.getPassword())) .password(bCryptPasswordEncoder.encode(memberDTO.getPassword()))
.role(MemberRole.getDefault()) .role(MemberRole.getDefault())
.build(); .build();
Long oid = generateOid();
member.setOid(oid);
member.setCreatedOid(oid);
Member savedMember = memberRepository.save(member); Member savedMember = memberRepository.save(member);

View File

@@ -6,10 +6,11 @@ import lombok.Setter;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import com.bio.bio_backend.global.utils.OidUtil;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import static com.bio.bio_backend.global.utils.OidUtil.generateOid;
/** /**
* 모든 엔티티가 상속받는 기본 엔티티 클래스 * 모든 엔티티가 상속받는 기본 엔티티 클래스
* 공통 필드들을 정의하고 JPA Auditing을 지원합니다. * 공통 필드들을 정의하고 JPA Auditing을 지원합니다.
@@ -40,14 +41,7 @@ public abstract class BaseEntity {
@PrePersist @PrePersist
protected void onCreate() { protected void onCreate() {
LocalDateTime now = LocalDateTime.now(); if(this.oid == null) this.oid = generateOid();
this.oid = OidUtil.generateOid(); if(this.createdOid != null && this.updatedOid == null) this.updatedOid = this.createdOid;
this.createdAt = now;
this.updatedAt = now;
}
@PreUpdate
protected void onUpdate() {
this.updatedAt = LocalDateTime.now();
} }
} }