由于我的实体有关系,@Query
可能出错?
哪个存储库包含错误。
使用名称' clickRepository':init的调用创建bean时出错 方法失败;嵌套异常是java.lang.IllegalArgumentException: 查询方法公共摘要的验证失败 java.lang.String中 com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String中,长)!
控制器
@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:错误 创建名称为&#39; clickController&#39;:注入自动装配的bean 依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 autowire字段:私有 com.qoobico.remindme.server.service.ClickService com.qoobico.remindme.server.controller.ClickController.service;嵌套 异常是org.springframework.beans.factory.BeanCreationException: 创建名称为&#39; clickServiceImpl&#39;:注入的bean时出错 自动连接依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 autowire字段:私有 com.qoobico.remindme.server.repository.ClickRepository com.qoobico.remindme.server.service.ClickServiceImpl.clickRepository; 嵌套异常是 org.springframework.beans.factory.BeanCreationException:错误 创建名称为“clickRepository&#39;”的bean:调用init方法 失败;嵌套异常是java.lang.IllegalArgumentException: 查询方法公共摘要的验证失败 java.lang.String中 com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String中,长)!
答案 0 :(得分:2)
您的参数名称不同。试试这个:
@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。