@Query,Repository中出错[英] Error in @Query , Repository

问题描述

由于我的实体有关系,@Query 中可能出现错误?存储库包含错误.

<块引用>

创建名为"clickRepository"的 bean 时出错:调用 init方法失败;嵌套异常是 java.lang.IllegalArgumentException:方法公共摘要的查询验证失败java.lang.Stringcom.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long)!

控制器

 @Autowired
private ClickService service;

/*
    i.e. information about fullname_client, id_banner sent to server from client
*/
@RequestMapping(value = "/sentemail", method = RequestMethod.POST)
@ResponseBody
public String sentClick(@RequestParam ("fullnameClient") String fullnameClient,@RequestParam ("idbanners") long idbanners) {

    return service.sent(fullnameClient, idbanners);
}

存储库

@Query("SELECT c.fullnameClient FROM Click AS c join c.idBanner Banners b WHERE b.idBanner = :idbanners AND c.fullnameClient = :fullnameClient")
String sent(@Param("fullnameClient") String fullnameClient, @Param("idbanners") long idbanners);

实体点击

@Id
@Column(name = "id_click", unique = true, nullable = false)
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private long idClick;

@ManyToOne(fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@JoinColumn(name = "id_banners", nullable = false)
private Banners idbanners;

@Column(name = "fullname_client", nullable = false, length = 50)
private String fullnameClient;

实体横幅

@Id
@Column(name = "id_banner", unique = true, nullable = false)
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private long idBanner;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "banners")
private Set<Businessbanner> businessbanners;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "idbanners")
private Set<Click> clicks;

错误

<块引用>

org.springframework.beans.factory.BeanCreationException: 错误创建名为"clickController"的bean:注入自动装配依赖失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:不能自动装配字段:私有com.qoobico.remindme.server.service.ClickServicecom.qoobico.remindme.server.controller.ClickController.service;嵌套的例外是 org.springframework.beans.factory.BeanCreationException:创建名为"clickServiceImpl"的 bean 时出错:注入自动装配依赖失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:不能自动装配字段:私有com.qoobico.remindme.server.repository.ClickRepositorycom.qoobico.remindme.server.service.ClickServiceImpl.clickRepository;嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建名为"clickRepository"的bean:调用init方法失败的;嵌套异常是 java.lang.IllegalArgumentException:方法公共摘要的查询验证失败java.lang.Stringcom.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long)!

推荐答案

您的参数名称不同.试试这个:

 @Query("SELECT c.fullnameClient FROM Click AS c join c.idbanners b WHERE b.idBanner = :idbanners AND c.fullnameClient = :fullnameClient")

    String sent(@Param("fullnameClient") String fullnameClient, @Param("idbanners ") long idbanners);

更新

好的,你的加入是错误的.. 而不是 c 加入 c.IdBanner.. 它应该是 c.idbanners.

本文地址:https://www.itbaoku.cn/post/978331.html