[Hotfix] 알림스케줄러에서 User의 firebase 토큰을 사용하려고 할 때 지연로딩되지 않는 현상 해결 #175
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
수정한 코드
@Transactional(readOnly = True)를 걸어주었음.findSchedulesStartingAt의 JPQL을 변경하였음.-(변경 전) FUNCTION 사용하여 약속을 가져와 DB에 종속적임.
-(변경 후) BETWEEN을 사용하여 약속을 가져와 DB에 독립적으로 실행될 수 있음.
발생했던 문제
Schedule에서getUser로 가져온User(프록시 객체)의firebaseToken을 사용(getFirebaseToken)하려는 순간 지연로딩 에러가 발생함.문제 원인
@Scheduled애너테이션이 별도의 스레드에서 실행되고 트랜잭션이 없어 영속성 컨텍스트가 없어Schedule에서User를 지연로딩할 수 없었음.(프록시 객체로만 존재)문제 해결
알림 스케줄러 전체에
@Transactional(readOnly = True)를 걸어@Scheduled가 포함된 메서드들이 트랜잭션이 적용되게 하여 영속성 컨텍스트가 생성되게 해 문제 해결하였음.