-
Notifications
You must be signed in to change notification settings - Fork 1
기존 Getter의 영향을 받아서 영속화 과정에서 원치않게 저장됨 #330
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
Conversation
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.
Summary of Changes
Hello @polyglot-k, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
이 풀 리퀘스트는 기존 Getter 메서드의 영향으로 phoneNumber 필드가 의도치 않게 영속화되는 문제를 해결합니다. phoneNumber 필드에 JPA 접근 유형을 FIELD로 명시적으로 설정함으로써, 영속성 공급자가 필드에 직접 접근하도록 하여 영속화 과정에서 발생할 수 있는 의도치 않은 부작용이나 잘못된 데이터 저장을 방지합니다.
Highlights
- JPA 영속성 수정: UserJpaEntity의 phoneNumber 필드에 JPA 접근 유형을 FIELD로 명시적으로 설정했습니다. 이는 기존 Getter로 인해 필드가 의도치 않게 영속화되는 문제를 해결하여, 영속화 시 필드에 직접 접근하도록 보장합니다.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
안녕하세요. phoneNumber 필드의 getter가 값을 변형하여, 영속화 과정에서 의도치 않은 값으로 저장되는 문제를 해결하기 위한 변경 사항을 잘 확인했습니다. @Access(AccessType.FIELD)를 사용하여 문제를 해결하신 것은 올바른 접근입니다. 다만, 코드의 가독성과 장기적인 유지보수성을 높이기 위해 근본적인 원인인 getter 메소드의 이름을 역할에 맞게 리팩토링하는 방안을 제안드렸습니다. 이렇게 하면 별도의 어노테이션 없이도 자연스럽게 문제를 해결할 수 있습니다. 자세한 내용은 코드 리뷰 코멘트를 참고해주세요.
| @Access(AccessType.FIELD) | ||
| private String phoneNumber; |
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.
이 변경으로 영속성 문제는 해결됩니다. 하지만 근본적인 원인은 getPhoneNumber() 메소드가 이름과 달리 필드 값을 그대로 반환하지 않고 변형하기 때문입니다. 이는 혼란을 야기하고 잠재적인 버그의 원인이 될 수 있습니다.
더 명확하고 유지보수하기 좋은 코드를 위해 관련 메소드들을 리팩토링하는 것을 고려해보시는 건 어떨까요? 예를 들어, 다음과 같이 수정할 수 있습니다.
getPhoneNumber()를getDisplayPhoneNumber()와 같이 변형된 값을 반환함을 명시하는 이름으로 변경합니다.getOriginPhoneNumber()를getPhoneNumber()로 변경하여 실제 필드 값을 반환하는 표준 getter 역할을 하도록 합니다.getPhoneNumberWithoutHyphen()에서는getDisplayPhoneNumber()를 호출하도록 수정합니다.
이렇게 리팩토링하면, JPA가 프로퍼티로 접근하더라도 표준 getter인 getPhoneNumber()를 호출하게 되어 원본 값이 올바르게 처리됩니다. 결과적으로 @Access(AccessType.FIELD) 어노테이션 없이도 문제를 해결할 수 있습니다.
리팩토링 예시:
// src/main/java/life/mosu/mosuserver/domain/user/entity/UserJpaEntity.java
// ...
// 이름 변경: getPhoneNumber -> getDisplayPhoneNumber
public String getDisplayPhoneNumber() {
return phoneNumber.replaceFirst("^[UG]", "");
}
public String getPhoneNumberWithoutHyphen() {
// 호출 메소드 변경
return getDisplayPhoneNumber().replaceAll("-", "");
}
// 이름 변경: getOriginPhoneNumber -> getPhoneNumber (표준 getter)
public String getPhoneNumber() {
return phoneNumber;
}
// ...이러한 리팩토링은 코드의 의도를 더 명확하게 만들어 장기적으로 도움이 될 것입니다.
기존 Getter의 영향을 받아서 영속화 과정에서 원치않게 저장됨