kmbin92_2025081101 #1
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@@ -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);
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user