[회원 엔티티 및 서비스 개선] - 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")
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.Map;
import static com.bio.bio_backend.global.utils.OidUtil.generateOid;
@Service
@RequiredArgsConstructor
@Slf4j
@@ -53,6 +55,10 @@ public class MemberServiceImpl implements MemberService {
.role(MemberRole.getDefault())
.build();
Long oid = generateOid();
member.setOid(oid);
member.setCreatedOid(oid);
Member savedMember = memberRepository.save(member);
return memberMapper.toMemberDto(savedMember);

View File

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