Merged
Conversation
kwdahun
approved these changes
Sep 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🌱 관련 이슈
🌱 작업 사항
JPA 엔티티의 생성 로직을 더 안전하고 명확하게 만들기 위해, 기존의 클래스 레벨
@Builder를 생성자 레벨@Builder로 전환하는 리팩토링을 진행했습니다.이 리팩토링을 통해 다음과 같은 문제점들을 해결하고 코드의 안정성을 높였습니다.
@GeneratedValue로 자동 생성되는 ID나@PrePersist로 관리되는 생성 시간 등을 빌더로 직접 주입하는 실수를 원천적으로 방지합니다.🌱 참고 사항
모든
@Entity클래스의@Builder를 생성자로 이동하고,각 엔티티의 역할과 특성에 따라 아래와 같은 기준으로 생성 규칙을 적용해 수정했습니다!
case 1️⃣ 일반 엔티티: 자동 생성 ID 및 기본값 필드 처리
기준:
@GeneratedValue로 ID가 자동 생성되고, 특정 필드에 기본값이 있는 가장 일반적인 엔티티입니다.♻️ 리팩토링 규칙:
@GeneratedValue가 붙은 ID 필드는 빌더에서 제외했습니다.status,role,isActive등 기본값이 필요한 필드는@Builder.Default대신 필드 선언 시 직접 초기화하여 엔티티가 스스로 기본 상태를 갖도록 수정했습니다.해당 엔티티:
case 2️⃣ ID 직접 할당 엔티티
기준:
@GeneratedValue없이, 애플리케이션에서 비즈니스 로직에 따라 ID를 직접 할당하는 엔티티입니다.♻️ 리팩토링 규칙:
생성 시점에 ID 값이 반드시 필요하므로, ID 필드를 빌더에 포함시켰습니다.
해당 엔티티:
case 3️⃣ 복합 키를 사용하는 조인 엔티티
기준: 두 엔티티를 연결하는 중간 테이블 역할을 하며,
@EmbeddedId와@MapsId를 사용하는 엔티티입니다.♻️ 리팩토링 규칙:
@EmbeddedId필드는 빌더에서 제외했습니다. (@MapsId가 연관 엔티티를 통해 자동으로 채워주기 때문에.)해당 엔티티:
case 4️⃣ 리팩토링 제외 대상: @embeddable ID 클래스
기준: 복합 키 자체를 정의하는 value용 객체입니다.
♻️ 리팩토링 규칙:
자동 생성되거나 기본값이 있는 필드가 없으며, ID 생성을 위해 모든 필드가 항상 필요하므로 리팩토링을 진행하지 않았습니다. 기존의
@AllArgsConstructor사용이 적합하다고 판단했습니다.해당 클래스:
추가 수정 사항
엔티티의 빌더 시그니처가 변경됨에 따라, 해당 빌더를 사용하던 일부 서비스 및 DTO 코드도 아래와 같이 수정했습니다.
DTO (
SaveRequestRequestDTO): 엔티티가 기본값을 스스로 설정하게 되면서, DTO의toEntity()메서드에서.status(Status.PENDING)처럼 중복으로 상태를 설정하던 코드를 제거했습니다.엔티티 내 비즈니스 메서드 (
Request.addGroup):@MapsId의 역할을 활용하도록, 복합 키를 직접 생성하여 빌더에 주입하던 코드를 제거하고 상위 엔티티만 전달하도록 간소화했습니다.