Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameter with that position [5] did not exist;

Tags:

java

mysql

spring

I'm trying to request some data in my database via a query, but all I get is this exception:

HTTP Status 500 - Request processing failed; nested exception is
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that position [5] did
not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that position [5]
did not exist

Well and this is my my MappingController

@RequestMapping(value="/vacChange", method = RequestMethod.POST)
public String changedVac(@RequestParam(value = "id", required = true) Integer id,
                         @RequestParam(value = "ort", required = true) String ort,
                         @RequestParam(value = "bereich", required = true) String bereich,
                         @RequestParam(value = "beschreibung", required = true) String beschreibung){
vacService.changeVacancyByID(id,gehalt,ort,bereich,beschreibung);


    return "vacAdmin";
}

I think I don't need to write down the ServiceClass but below is the ServiceClassImplementation

public void changeVacancyByID(Integer id, String gehalt,String ort,String bereich,String beschreibung){
        System.out.println("Edit method called");
        VacancyEntity vacEntity = vacancyRepository.findOneById(id);
        vacancyRepository.updateAttributes(id,gehalt,ort,bereich,beschreibung);

}

Last but not least this is my repository:

@Transactional
@Query (value = "UPDATE vacancy SET salary=?1, location=?2,functionality=?3, description=?4 WHERE id = ?0  ", nativeQuery = true)
VacancyEntity updateAttributes(Integer id, String gehalt, String ort, String bereich, String beschreibung);
like image 703
Stan Avatar asked May 28 '15 15:05

Stan


1 Answers

Position based parameters start with 1, try with this

@Query (value = "UPDATE vacancy SET salary=?1, location=?2,functionality=?3, description=?4 WHERE id = ?5  ", nativeQuery = true)
VacancyEntity updateAttributes(String gehalt, String ort, String bereich, String beschreibung, Integer id);

or, with unchanged method signature

@Query (value = "UPDATE vacancy SET salary=?2, location=?3,functionality=?4, description=?5 WHERE id = ?1  ", nativeQuery = true)
like image 54
Predrag Maric Avatar answered Oct 18 '22 04:10

Predrag Maric