REST 컨트롤러에서 Customer 오브젝트 아래에서 삭제하려고 할 때 "분리 된 인스턴스 제거" 예외.삭제시 detached 인스턴스 오류 제거
LOG :
org.springframework.dao.InvalidDataAccessApiUsageException: Removing a detached instance com.test.model.Customer#1750; nested exception is java.lang.IllegalArgumentException: Removing a detached instance com.test.model.Customer#1750
도메인 :
@Entity
public class Customer{
@Id
private Long id;
@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name="COUNTRY_ID", nullable=false)
private Country country;
// other stuff with getters/setters
}
REST 컨트롤러 :
@Controller
@RequestMapping("/shop/services/customers")
public class CustomerRESTController {
/**
* Deletes a customer
*/
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteCustomer(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response) throws Exception {
Customer customer = customerService.getById(id);
if(customer != null){
customerService.delete(customer);
}else{
response.sendError(503, "No Customer found for ID : " + id);
}
}
// other stuff
}
I 얻고 고객 그러나 데이터베이스의 개체는 여전히 동면하는 동면 상태입니다. 제안 사항 ??
'customerService' 코드를 표시 할 수 있습니까? –
물론 ....여기있다 :'@Service ("CustomerService를") 공용 클래스 CustomerServiceImpl { \t 공공 고객 getById (긴 ID) { \t \t \t 반환 customerDAO.getById (ID); \t \t \t} } –