-
Notifications
You must be signed in to change notification settings - Fork 2
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
회원 관련 엔티티 추가 (그리고 H2 환경 추가) #8
base: develop
Are you sure you want to change the base?
Conversation
public class BooleanToYOrNConverter implements AttributeConverter<Boolean, String> { | ||
@Override | ||
public String convertToDatabaseColumn(Boolean attribute) { | ||
return attribute ? "Y" : "N"; |
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.
AttributeConverter
라니..! 새로운걸 배워갑니다!
그런데 만약 Boolean attribute
가 null
이면 조건식이 어떻게 되는건가요?
별도의 NPE 체크 없이 사용 가능한가요??
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.
당연히 안되겠죠^^;
좋은 지적 감사합니다, 수정할게요. 항상 대충하는 버릇이...
코드 리뷰 하니까 좋네요, 성준님😍
|
||
@Override | ||
public Boolean convertToEntityAttribute(String dbData) { | ||
return dbData.equals("Y"); |
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.
만약 dbData
값이 null 이면 NPE 가 발생할 것 같습니다..!
"Y".equals(dbData);
로 해 보시는 것은 어떨까요?
(또는 StringUtils
등을 적극 활용해보는 것도 좋을 것 같습니다!!)
요즘 NPE 로 고생중이라 JPA 외적인 부분들만 눈에 들어오네요 ㅠㅠ
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.
최근에 저도 실무에 코딩 가이드 적용하면서 NPE 지적을 엄청 받았으면서 또 이랬어요.
수정할게요~
정상적으로 테이블이 생성되는지 확인해보려고 일단 H2 설정 넣었어요.
회원 관련 엔티티 생성하였습니다.
그리고,
boolean
타입을 대응하는Converter
생성했어요.