【问题标题】:Spring boot factoryBean threw exception on object creationSpring Boot factoryBean 在创建对象时抛出异常
【发布时间】:2021-08-24 07:21:33
【问题描述】:

下面的java代码“应该通过spring boot在sql数据库上执行”来执行它我使用下面的存储库,但是当我运行代码时出现以下错误,我该如何修复它以及它是什么由于?

错误:

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);
    }

【问题讨论】:

  • 没有您的实体,这是不可能回答的。
  • 如果spring-boot版本是2需要更新,@Query(nativeQuery = true, value = "your sql_query")

标签: java spring spring-boot java-8


【解决方案1】:

它在该标签中期望HQL,而不是SQL

尝试更改为

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

【讨论】:

    猜你喜欢
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 2016-09-26
    • 2019-09-19
    • 1970-01-01
    • 2019-01-24
    相关资源
    最近更新 更多