我正在尝试使用他的电子邮件更新客户密码,在我更新后,我希望ResponseEntity
在修改完成后返回整个客户对象。
但我对邮递员有这个错误:
"error": "Internal Server Error",
"error_description": [
"could not execute batch; SQL [insert into tcustomer (authentication_uid, creation_date, attribute_uid, default_payment_method_uid, guid, last_edit_date, pref_bill_address_uid, pref_ship_address_uid, status, storecode, type, user_id, uidpk) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute batch"
]
我正在传递带有密码和电子邮件的JSON:
{
"password": "miam",
"userId": "ton.nya@yahoo.fr"
}
这里是serviceImpl:
public CustomerDto updateCustomerPassword( String userId, String password) {
CustomerAuthentication customerAuthentication = new CustomerAuthentication();
customerAuthentication.setPassword(password);
Customer customer = new Customer();
customer.setAuthenticationUid(customerAuthentication);
customer.setUserId(userId);
Customer result = customerRepository.save(customer);
return customerMapper.customerToCustomerDto(result);
}
这里是资源
@PutMapping(CUSTOMER_ENDPOINT)
@ResponseStatus(value = HttpStatus.NO_CONTENT)
@ApiResponses(value = {
@ApiResponse(code = 201, message = "The Customer has been created", response = CustomerDto.class),
@ApiResponse(code = 204, message = "The Customer has been updated", response = CustomerDto.class),
@ApiResponse(code = 500, message = "Unexpected error")
})
@Timed
public ResponseEntity updateCustomer(final HttpServletRequest request, @RequestBody String userId, String password)throws MethodArgumentNotValidException{
log.debug("[CustomerResource] PUT {} Updating Customer", CUSTOMER_ENDPOINT);
CustomerDto result = customerService.updateCustomerPassword(userId,password);
log.debug("[CustomerResource] Customer ({}) Updated",result.getUidpk());
return new ResponseEntity<>(result,null, HttpStatus.NO_CONTENT);
}
还有其他解决方案吗?感谢。