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

也许由于我的实体具有关系而在@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)!

调节器

 @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-如何在Spring Data JPA中跳过@Query中的@Param是否为空或为空


下一篇:springcloud