-
Notifications
You must be signed in to change notification settings - Fork 3
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
Study Repository 외래키 조회 네이밍 수정 #108
Open
HanKwanJin
wants to merge
1
commit into
main
Choose a base branch
from
refactor/#107/fk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
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.
이렇게 되면 굳이 Study 도메인 객체를 찾아오지 않고도 조회가 되니 쿼리를 줄일 수 있어 좋은 것 같아요!
너무 좋았습니다!
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.
혹시 쿼리도 실제로 잘 나가는지 확인해보셨나요? 갑자기 궁금해서 질문 남깁니다!
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.
저도 확인을 안해봤어서 방금 확인 결과 (예시)findByStudyId 와 findByStudy_Id 둘의 쿼리는 위와 동일하게 나갑니다.
그렇다면 왜 _ 을 붙여서 네이밍을 해야할까?
궁금해서 이에 대한 답도 찾아봤습니다.
이슈에 작성한 내용에서 말했듯이 JPA에서 외래키를 가진 엔티티를 조회할 때,
_
를 붙이는 네이밍 규칙이 있습니다.예를 들어,
StudyMember
엔티티에서study
필드가 외래키를 가지고 있다면, 해당 필드의 이름은study_id
로 작성해야 합니다.이렇게 함으로써, JPA는 자동으로 외래키를 찾아 매핑하는 과정을 수행할 수 있습니다.
findByStudyId 메서드또한 StudyMember 엔티티에서 study_id 필드를 조회하는 방법입니다.
하지만, 필드명과 외래키 컬럼명이 일치하지 않는 경우에는,
@JoinColumn
어노테이션을 사용하여 직접 매핑 정보를 지정해주어야 합니다. 따라서,_
를 포함하는 네이밍 규칙을 지키는 것이 좋습니다. 이렇게 함으로써, 코딩 컨벤션을 일관성 있게 유지할 수 있으며, 가독성도 높아집니다.