Skip to content

Commit

Permalink
Fix: Spring Data Jdbc에서 save 메서드를 통해서 update 할 때 PK를 List의 index 값으로 …
Browse files Browse the repository at this point in the history
…입력되는 오류 수정

update 쿼리를 직접 작성해서 사용하는 방식으로 해당 문제를 해결했습니다.
  • Loading branch information
Louie-03 committed Apr 26, 2022
1 parent d5c67f6 commit 921e065
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
@@ -1,6 +1,7 @@
package sidedish.com.repository;

import java.util.List;
import org.springframework.data.jdbc.repository.query.Modifying;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
Expand All @@ -16,4 +17,8 @@ public interface ProductsRepository extends CrudRepository<ProductEntity, Long>
List<ProductEntity> findByMealType(@Param("mealType") String mealType);

List<ProductEntity> findAllByBestCategory(String category);

@Modifying
@Query("update PRODUCT set stock_quantity = :stockQuantity where id = :id")
void update(@Param("stockQuantity") long stockQuantity, @Param("id") Long id);
}
2 changes: 1 addition & 1 deletion BE/src/main/java/sidedish/com/service/OrderService.java
Expand Up @@ -38,7 +38,7 @@ public OrderSaveResponse save(Long productId, long count) {
Order order = new Order(product, count);
OrderEntity orderEntity = domainEntityMapper.toOrderEntityFromDomain(order);

productsRepository.save(domainEntityMapper.toProductEntityFromDomain(product));
productsRepository.update(product.getStockQuantity(), product.getId());
return domainDtoMapper.toOrderSaveResponseFromOrder(orderRepository.save(orderEntity));
}
}

0 comments on commit 921e065

Please sign in to comment.