Search code examples
javaspringspring-mvcspring-data-jpajpql

Click underlined in red, @Query, JpaRepository


And another point. How to create a complex query like this?

SELECT businesscentr.email
FROM businesscentr, banners, businessbanner, click
WHERE click.id_banner = banners.id_banner AND banners.id_banner =  businessbanner.id_banner AND businessbanner.id_bc = businesscentr.id_bc

Repository extends JpaRepository<Click, Long>.

@Query("select c from Click c where c.id_bannners = :idbanners and c.fullname_client = :fullnameClient")

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

Error

 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.IllegalStateException: Using named parameters for method public abstract java.lang.String com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long) but parameter 'fullname_client' not found in annotated query 'select c from Click c where c.id_bannners = :idbanners and c.fullname_client = :fullnameClient'!
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
    at 

Solution

  • The problem is that your param names don't match your query parameter names

    You have

      @Query("select c from Click c where c.id_bannners = :idbanners and c.fullname_client = :fullnameClient")
        String sent(@Param("fullname_client") String fullnameClient, @Param("id_banner") long idbanners);
    

    You shoud have

     @Query("select c from Click c where c.id_bannners = :id_banner and c.fullname_client = :fullname_client")
        String sent(@Param("fullname_client") String fullnameClient, @Param("id_banner") long idbanners);
    

    That's how parameters and query match between each other