Skip to content

Conversation

@worhs02
Copy link
Collaborator

@worhs02 worhs02 commented Oct 27, 2025

🔗 관련 이슈

연관된 이슈 번호를 적어주세요. (예: #123)


📌 PR 요약

PR에 대한 간략한 설명을 작성해주세요.
(예: 해당 변경 사항의 목적이나 주요 내용)


📑 작업 내용

작업의 세부 내용을 작성해주세요.

  1. 작업 내용 1
  2. 작업 내용 2
  3. 작업 내용 3

스크린샷 (선택)


💡 추가 참고 사항

PR에 대해 추가적으로 논의하거나 참고해야 할 내용을 작성해주세요.
(예: 변경사항이 코드베이스에 미치는 영향, 테스트 방법 등)

worhs02 and others added 3 commits October 26, 2025 14:31
- MemberServiceImpl의 findById(), findMemberByEmail() 메서드에 @transactional(readOnly = true) 적용
- LogBookService의 getLogBooksByYearAndStatus(), getLogBooks() 메서드에 @transactional(readOnly = true) 적용

근본 원인:
- Member 엔티티는 @Version 필드를 가짐 (optimistic locking)
- 클래스 레벨 @transactional로 인해 읽기 메서드도 write transaction에서 실행됨
- Write transaction 내에서 @Cacheable로 캐싱된 Member 엔티티가 detached되면서 version 필드 초기화 문제 발생
- 에러: "Detached entity with generated id has an uninitialized version value 'null'"

해결 방법:
- 읽기 전용 메서드에 명시적으로 @transactional(readOnly = true) 적용
- 캐시와 JPA 트랜잭션 간 호환성 향상
- 불필요한 write lock 방지로 성능 최적화
캐시에서 가져온 detached Member 엔티티를 저장할 때 @Version 필드가 null이어서
ObjectOptimisticLockingFailureException이 발생하는 문제 수정

변경 사항:
- findById(): @transactional(readOnly=true) 제거하여 managed entity 반환
- saveMember(): detached entity 감지 시 DB에서 재조회 후 필드 복사
- updateLevel/requestToDeleteMember/cancelDeleteMember: @CacheEvict에 beforeInvocation=false 명시하여 캐시 무효화 타이밍 명확화
…n-error

fix/#194: 캐시 트랜잭션 오류 수정
@worhs02 worhs02 requested a review from sereene October 27, 2025 01:18
Copy link
Collaborator

@sereene sereene left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

@worhs02 worhs02 merged commit 9f8b499 into main Oct 27, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants