-
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
feat: Modifying Annotation 트러블 슈팅 글 작성 #5
feat: Modifying Annotation 트러블 슈팅 글 작성 #5
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.
쥬니 글 잘 읽었어요!
많이 배워가는 글이었습니다~!
서비스 계층에서 데이터를 삭제하는 테스트를 수행하는 도중, 데이터가 삭제되지 않고 조회되는 문제가 발생하였습니다. | ||
<br> 지금부터, 그 이야기를 시작해 보려 합니다. |
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.
흥미진진하네요
(1) `@Query` 어노테이션을 사용하여 직접 쿼리를 작성하는 방법과, (2) 테스트 코드에서 flush & clear를 명시적으로 수행하는 방법이 있었습니다. | ||
<br> 단순히 테스트 통과에 목적을 둔 것이 아니기 때문에, 실제 프로덕트 코드에서도 예상치 못한 동작을 방지하기 위해 (1)번 방법을 선택하였습니다. | ||
<br> 이에 따라, `Named Query -> JPQL`로 변경함으로써 문제를 해결할 수 있었습니다. | ||
```java | ||
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> { | ||
@Modifying(clearAutomatically = true) | ||
@Query("delete from Bookmark b where b.member.id = :memberId") | ||
void deleteAllByMemberId(@Param(value = "memberId") Long memberId); | ||
} |
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.
지금까지는 굉장히 운이 좋았던거군요!
이거 덕분에 저번에 RefreshToken 삭제가 왜 안되었었는지 알았어요!
아주 좋은 글입니다
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.
문제 해결 방식이 돋보이는 좋은 글이네용 ~
@Query
때문이었다니..
문제 해결 & 지식 전파 감사합니다 👍👍
바로보기