gpt4 book ai didi

java - @Query 和存储库中的错误

转载 作者:行者123 更新时间:2023-11-30 02:40:33 24 4
gpt4 key购买 nike

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

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)!

Controller

 @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: 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)!

最佳答案

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

 @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。

关于java - @Query 和存储库中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41874743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com