Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HQLTester': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.service.CompanyRepository com.example.HQLTester.companyRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.CompanyRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
- at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
- at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
- at com.example.HqlTesterApplication.main(HqlTesterApplication.java:18) [classes/:na]
- Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.service.CompanyRepository com.example.HQLTester.companyRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.CompanyRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- ... 16 common frames omitted
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.service.CompanyRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
- ... 18 common frames omitted
- @SpringBootApplication
- @ComponentScan("com.*")
- @Configuration
- @EnableJpaRepositories("com.service.*")
- public class HqlTesterApplication {
- public static void main(String[] args) {
- SpringApplication.run(HqlTesterApplication.class, args);
- }
- }
- @Service
- public class HQLTester {
- @Autowired
- CompanyRepository companyRepository;
- @PostConstruct
- void testHQL(){
- System.out.println("TEST");
- List<Company> companies = companyRepository.findCompanyWithEmployes2(new Date(), 1l);
- List<Company> companies2 = companyRepository.findCompanyWithEmployes(new Date(), 1l);
- }
- }
- public interface CompanyRepository extends JpaRepository<Company, Long> {
- @Query(" SELECT c FROM Company c ,Employee e LEFT JOIN FETCH c.employees emp WHERE e.id=emp.id and e.hireDate > :dateee and e.departureDate < :dateee and c.id=:id")
- List<Company> findCompanyWithEmployes2(@Param("dateee") Date dateee, @Param("id") Long id);
- @Query(" SELECT c FROM Employee e LEFT JOIN FETCH e.company c WHERE e.hireDate > :dateee and e.departureDate < :dateee and c.id=:id")
- List<Company> findCompanyWithEmployes(@Param("dateee") Date dateee, @Param("id") Long id);
- }
- @Entity
- public class Company {
- @Id
- Long id;
- String name;
- @OneToMany(mappedBy = "company", cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
- private Set<Employee> employees;
- }
- @Entity
- public class Employee {
- @Id
- Long id;
- String name;
- Date hireDate;
- Date departureDate;
- @ManyToOne
- @JoinColumn(name = "companyId", insertable = false, updatable = false)
- Company company;
- }
- spring.datasource.url:jdbc:oracle:thin:@//myServer.com:1521/TESTDB
- spring.datasource.username=TESTUSER
- spring.datasource.password=TESTUSER
- spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
- spring.jpa.hibernate.ddl-auto=none
- spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
- spring.jpa.show-sql = true
- logging.level.org.springframework.data=DEBUG
- @Repository
- public interface CompanyRepository extends JpaRepository<Company, Long> {
- @Query(" SELECT c FROM Company c ,Employee e LEFT JOIN FETCH c.employees emp WHERE e.id=emp.id and e.hireDate > :dateee and e.departureDate < :dateee and c.id=:id")
- List<Company> findCompanyWithEmployes2(@Param("dateee") Date dateee, @Param("id") Long id);
- @Query(" SELECT c FROM Employee e LEFT JOIN FETCH e.company c WHERE e.hireDate > :dateee and e.departureDate < :dateee and c.id=:id")
- List<Company> findCompanyWithEmployes(@Param("dateee") Date dateee, @Param("id") Long id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement