Issue
the java code below "should execute" the select on a sql database via spring boot to do it I use the repository below, but when I run the code I have the following error, how can I fix it and what is it due to?
Error:
Error creating bean with name 'rapportoRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.reportserver.report.repository.RapportoRepository.findbycantiere(int)!
RapportoRepository.java:
public interface RapportoRepository extends JpaRepository<Rapporto, Integer> {
//Permette il caricamento dei rapportini presenti in un cantiere
@Query("SELECT * FROM Rapporto where IdCantiere=:IdCantiere")
List<Rapporto> findbycantiere(@Param("IdCantiere") int IdCantiere);
}
ReportService.java
@Description(value = "Report Cantieri")
@RestController
@RequestMapping("/api/report")
public class ReportResource {
@PostMapping(value = "/stampa/rapportini")
public @ResponseBody
ResponseEntity<Object> stamparapportini(@Valid @RequestBody Cantiere cantierereport) throws JSONException {
System.out.println("\n Chiamata a servizio rest stampa rapportini");
List<Rapporto> listlp= rapportoRepository.findbycantiere(cantierereport.getIdCantiere());
List<JSONObject> entities = new ArrayList<JSONObject>();
for (Rapporto rp : listlp) {
JSONObject entity = new JSONObject();
entity.put("IdRapporto", rp.getId());
entity.put("Immagine", rp.getImmagine());
entities.add(entity);
}
return new ResponseEntity<Object>(entities, HttpStatus.OK);
}
Solution
It expect HQL
, not SQL
in that tag.
Try change to
@Query("FROM Rapporto where IdCantiere=:IdCantiere").
List<Rapporto> findbycantiere(@Param("IdCantiere") int IdCantiere);
Answered By - talex
Answer Checked By - Senaida (JavaFixing Volunteer)