@Query 中的错误,存储库 [英] Error in @Query , Repository

查看:19
本文介绍了@Query 中的错误,存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许 @Query 中的错误是因为我的实体有关系?其中存储库包含错误.

Maybe error in @Query due to the fact that my entity have relation ? Which the Repository contain error.

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

Error creating bean with name 'clickRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.lang.String com.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:查询方法公共抽象验证失败字符串com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long)!

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clickController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.qoobico.remindme.server.service.ClickService com.qoobico.remindme.server.controller.ClickController.service; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clickServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.qoobico.remindme.server.repository.ClickRepository com.qoobico.remindme.server.service.ClickServiceImpl.clickRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clickRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.lang.String com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long)!

推荐答案

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

Your param names differ. Try this:

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

更新

好吧,你的 join 错了.. 而不是 c join c.IdBanner.. 应该是 c.idbanners.

Ok your join was wrong.. instead of c join c.IdBanner.. it should be c.idbanners.

这篇关于@Query 中的错误,存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆