π€ λ¬Έμ μν©
μν μμ κΈ°λ₯μ ꡬν ν ν μ€νΈ μΌμ΄μ€λ₯Ό λλ €λ³΄λ €κ³ νλλ° μλμ κ°μ μ€λ₯κ° μ겨μ ν΄κ²°λ΄μ©μ μ 리νμλ€.
// μμ±ν ν
μ€νΈ μΌμ΄μ€
@Test
@DisplayName("μν μμ νμΈ")
void t3() {
// When
cartService.deleteCartItem(23L);
List<CartItem> cartItemList = cartService.findAllByMemberId(2L);
// Then
assertThat(cartItemList.size()).isEqualTo(0);
}
// Service μ½λ
public class CartService {
// (μλ΅)
public void deleteCartItem(Long uniqueId) {
CartItem cartItem = cartRepository.findByIndexUnique(uniqueId).orElse(null);
if (cartItem == null) {
throw new NotFoundException();
}
cartRepository.delete(cartItem);
}
}
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with
// (μλ΅)
java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.Optional com.ll.exam.final__2022_10_08.app.cart.repository.CartRepository.findByIndexUnique(java.lang.Long)! No property 'indexUnique' found for type 'CartItem' Did you mean ''index_unique''
λμΆ© λ€λ₯Έκ±΄ μλ΅νκ³ λ§μ§λ§μ 보λ Service μ findByIndexUnique λΆλΆμμ CartItem Entity μ 컬λΌμ μΈμνλ κ²μ λ¬Έμ κ° μλ κ² κ°μλ€.
@Entity
public class CartItem extends BaseEntity {
@ManyToOne
private Member member;
@ManyToOne
private Product product;
private Long index_unique;
}
index_unique λ‘ λμ΄μμλλ° λ€μν findByλ¬Έμ μ¨λ΄λ Index_unique λ‘ μΈμμ λͺ»νκΈΈλ κ·Έλ₯ 컬λΌλͺ μ indexUnique λ‘ λ°κΎΈμ΄ μ£Όμλ€.
// μμ μ
@Entity
public class CartItem extends BaseEntity {
// (μλ΅)
private Long indexUnique;
}
μ΄λ κ² μμ ν λ€ λκ°μ΄ ν μ€νΈ μΌμ΄μ€λ₯Ό μ€νμμΌλ³΄λ μ λμκ°λ€!
'μ€λ΅λ ΈνΈ π' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
| (JPA) μ뱑ν₯ κ΄κ³μ μν μν μ°Έμ‘° λ¬Έμ ν΄κ²° (Could not write JSON: Infinite recursion) (0) | 2022.10.13 |
|---|---|
| (h2 DB) H2 DB μ€μ μ΄κΈ°ν νλλ² (0) | 2022.10.07 |