-
Notifications
You must be signed in to change notification settings - Fork 0
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
[39] 주문 전 재고 체크 및 재고 감소 #42
[39] 주문 전 재고 체크 및 재고 감소 #42
Conversation
@Repository | ||
public interface ProductRepository extends JpaRepository<Product, Long> { | ||
@Lock(LockModeType.PESSIMISTIC_WRITE) | ||
@Query("SELECT p FROM Product p WHERE p.id IN :productIds") | ||
List<Product> findByIdIn(List<Long> productIds); |
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.
Lock을 잡는 쿼리와 아닌 쿼리는 메소드 레벨에서 구분하는게 좋습니다. 의도치 않게 lock을 잡는 실수를 방지할 수 있습니다.
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.
findByIdInWithLock 으로 메소드 이름을 변경했습니다..!
.map(OrderRequestDto.CreateDetail::getProductId) | ||
.toList(); | ||
|
||
List<Product> products = productRepository.findByIdIn(productIds); |
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.
여기서 잡은 lock은 언제까지 유효할까요?
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.
트랜잭션어노테이션으로 지정한 부분이 종료 될때까지 유효한걸로 알고 있습니다!
No description provided.