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

前端 未结 2 1735
有刺的猬
有刺的猬 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:28

    It appears that the problem was that Map<ContentType, Integer> does not have a promise of a unique index, so JPA doesn't like mapping to it. By using List<Map<ContentType, Integer>> instead, it works great!

    0 讨论(0)
  • 2021-02-19 15:41

    Try this it works

    keep your model in list

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

    then in your repository

    @Override
    public void delete(List<Driver> delete_driver) {
    
        driverRepository.delete(delete_driver);
    }
    
    0 讨论(0)
提交回复
热议问题