Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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);
                If spring-boot version is 2 you need to update, @Query(nativeQuery = true, value = "your sql_query")
– Another coder
                Aug 24, 2021 at 7:55

It expect HQL, not SQL in that tag.

Try change to

@Query("FROM Rapporto where IdCantiere=:IdCantiere").
List<Rapporto> findbycantiere(@Param("IdCantiere") int IdCantiere);
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.