-
Notifications
You must be signed in to change notification settings - Fork 8
fix: 채널 수정 시 유니크 제약 위반하지 않도록 #426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: 채널 수정 시 유니크 제약 위반하지 않도록 #426
Conversation
Walkthrough
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/com/example/solidconnection/mentor/domain/Channel.java(1 hunks)src/main/java/com/example/solidconnection/mentor/domain/Mentor.java(1 hunks)src/test/java/com/example/solidconnection/mentor/service/MentorMyPageServiceTest.java(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/main/java/com/example/solidconnection/mentor/domain/Channel.java
- src/test/java/com/example/solidconnection/mentor/service/MentorMyPageServiceTest.java
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: nayonsoso
PR: solid-connection/solid-connect-server#375
File: src/main/java/com/example/solidconnection/mentor/service/MentorMyPageService.java:47-53
Timestamp: 2025-07-05T17:54:42.475Z
Learning: MentorMyPageService에서 PUT 메서드 구현 시 전체 채널을 새로 생성하여 교체하는 방식을 사용하는 것이 PUT의 의미론적 특성과 일치하며, 트랜잭션 로킹 관점에서도 합리적인 접근이다.
📚 Learning: mentormypageservice에서 put 메서드 구현 시 전체 채널을 새로 생성하여 교체하는 방식을 사용하는 것이 put의 의미론적 특성과 일치하며, 트랜잭션 로킹 관점에서도...
Learnt from: nayonsoso
PR: solid-connection/solid-connect-server#375
File: src/main/java/com/example/solidconnection/mentor/service/MentorMyPageService.java:47-53
Timestamp: 2025-07-05T17:54:42.475Z
Learning: MentorMyPageService에서 PUT 메서드 구현 시 전체 채널을 새로 생성하여 교체하는 방식을 사용하는 것이 PUT의 의미론적 특성과 일치하며, 트랜잭션 로킹 관점에서도 합리적인 접근이다.
Applied to files:
src/main/java/com/example/solidconnection/mentor/domain/Mentor.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
src/main/java/com/example/solidconnection/mentor/domain/Mentor.java (1)
67-83: 승인: Channel.update()에서 sequence 필드를 포함한 모든 속성 업데이트가 확인되었습니다.
Shell 스크립트 결과, update 메서드가 sequence, type, url을 모두 올바르게 복사함을 검증했습니다.
기존 채널 업데이트, 새 채널 추가, 초과 채널 제거 로직이 유니크 제약을 안전하게 유지합니다.
머지 진행 부탁드립니다.변경 사항 요약:
- Channel.update() 검증
- sequence, type, url 복사 확인
- 기존 채널 업데이트
- this.channels.get(i).update(channel)로 안전한 동기화
- 새 채널 추가
- updateMentor() 호출 후 리스트 끝에 추가
- 초과 채널 제거
- 뒤에서부터 순차적으로 remove 호출
2935a99 to
63b6b1e
Compare
63b6b1e to
e6dffc9
Compare
whqtker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋은 변경입니다 !
clear 후 flush 를 수행해도 과연 동일하게 동작할까요 ..?
@whqtker 네 맞습니다! 다만 영속성 컨텍스트를 주입받아야 한다는 점이 걸렸어요😅 |
관련 이슈
트러블 슈팅 과정
멘토의 마이 페이지 수정 시, 채널을 변경할 때 'unique 제약조건 위반'이 발생했습니다.

Channels 엔티티를 보면 아시겠지만, mentor_id와 sequence 조합으로 unique 제약조건을 설정해둔 상태였습니다.
코드 자체만 봤을 때는 “🤔removeAll 후 add 를 하고 있으니, 문제가 없지 않나?” 싶었습니다.
Hibernate 공식 문서에도 컬렉션에 있어서는 delete 문이 먼저 실행된다고 되어있어, 원인을 파악하기 어려웠습니다..

진짜 문제는 기존의 코드에서는 new Channel()로 완전히 새로운 객체를 만들어 넣었다는 것이었습니다.
이때문에 4번인 insertion of collection elements 가 아니라 1번의 insert로 인식되어서 delete 보다 먼저 실행되었습니다.
이 문제를 해결하기 위해
를 하도록 코드를 수정했습니다.
또한 테스트 코드를 보충했습니다.