Skip to content
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

[BE] refactor: 트랜잭션을 팀 컨벤션에 맞게 리팩터링 #291

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

70825
Copy link
Member

@70825 70825 commented Aug 3, 2023

Issue

✨ 구현한 기능

  • 클래스단에 readOnly = true 추가
  • findOrCreateMember에 @Transactional 추가
  • save에 @Transactional(propagtion=REQUIRES_NEW) 제거

같은 클래스에서 findOrCreateMember 호출하고, 내부에서 save를 호출하면 save 메서드 위에 적혀있는 @Transactional이 적용되지 않습니다.
왜냐하면 스프링 트랜잭션 공식 문서에서 아래와 같은 내용이 나와있습니다.
그래서 프록시로 호출하기 때문에 같은 클래스 내부에 부모 메서드 호출 -> 자식 메서드를 호출하면 자식 메서드에 적혀있는 트랜잭션이 무시됩니다.

In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted.
This means that self-invocation (in effect, a method within the target object calling another method of the target object) does not lead to an actual transaction at runtime even if the invoked method is marked with @transactional.
Also, the proxy must be fully initialized to provide the expected behavior, so you should not rely on this feature in your initialization code — for example, in a @PostConstruct method.

만약 이게 적용이 안된다면 findOrCreateMember에 @Transactional이 아닌 @Transactional(propagation=REQUIRES_NEW)로 설정해야합니다.

  • REQUIRES_NEW : 부모 트랜잭션이 존재하면, 부모 트랜잭션을 중지하고, 새로운 트랜잭션을 생성하고 실행함. 새로운 트랜잭션이 종료되었으면 부모 트랜잭션을 다시 실행함

📢 논의하고 싶은 내용

  • x

🎸 기타

  • x

⏰ 일정

  • 추정 시간 : 0.1
  • 걸린 시간 : 0.1

@70825 70825 self-assigned this Aug 3, 2023
@github-actions
Copy link

github-actions bot commented Aug 3, 2023

Unit Test Results

67 tests   67 ✔️  11s ⏱️
34 suites    0 💤
34 files      0

Results for commit 36a3f72.

Copy link
Collaborator

@hanueleee hanueleee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

신기하네요 자식 트랜잭션 무시..
새로운 사실 알아갑니다~~

Copy link
Collaborator

@Go-Jaecheol Go-Jaecheol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

역시 트랜잭션 권위자..👍

Copy link
Collaborator

@wugawuga wugawuga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM~👍

@70825 70825 merged commit d127270 into develop Aug 3, 2023
3 checks passed
@70825 70825 deleted the feat/issue-283 branch August 3, 2023 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BE] 로그인 서비스 로직 트랜잭션 컨벤션에 맞게 리팩터링
4 participants