JPA Repository: javax.persistence.NonUniqueResultException: result returns more than one elements

前端 未结 2 1736
有刺的猬
有刺的猬 2021-02-19 15:06

Using the below code I am unable to get the results of my query. Whether I use Map or Map I get the same error: javax.p

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 15:41

    Try this it works

    keep your model in list

    @RequestMapping(value="/deleteDriver/{id}" , method=RequestMethod.POST)
    public ResponseEntity deleteDriver(@PathVariable("id") Integer id)
    {
        List delete_driver=adminService.getDriverById(id);
        Map response=new HashMap<>();
    
    
        if(delete_driver==null)
        {
            response.put("status", "Failure");
            return new ResponseEntity(response,HttpStatus.NO_CONTENT);
        }
        else
        {
            response.put("status", "Success");
            adminService.delete(delete_driver);
            return new ResponseEntity(response,HttpStatus.OK);
        }
    
    }
    
    
    

    then in your repository

    @Override
    public void delete(List delete_driver) {
    
        driverRepository.delete(delete_driver);
    }
    

    提交回复
    热议问题