Advertisement
Guest User

Untitled

a guest
Jul 4th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | None | 0 0
  1. 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)}
  2. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  3. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  4. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  5. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  6. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  7. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  8. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  9. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  10. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  11. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  12. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  13. at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
  14. at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
  15. at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
  16. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
  17. at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.5.RELEASE.jar:1.3.5.RELEASE]
  18. at com.example.HqlTesterApplication.main(HqlTesterApplication.java:18) [classes/:na]
  19. 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)}
  20. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  21. at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  22. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  23. ... 16 common frames omitted
  24. 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)}
  25. at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  26. at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  27. at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  28. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  29. ... 18 common frames omitted
  30.  
  31. @SpringBootApplication
  32. @ComponentScan("com.*")
  33. @Configuration
  34. @EnableJpaRepositories("com.service.*")
  35. public class HqlTesterApplication {
  36.  
  37. public static void main(String[] args) {
  38. SpringApplication.run(HqlTesterApplication.class, args);
  39. }
  40.  
  41. }
  42.  
  43. @Service
  44. public class HQLTester {
  45.  
  46. @Autowired
  47. CompanyRepository companyRepository;
  48.  
  49. @PostConstruct
  50. void testHQL(){
  51. System.out.println("TEST");
  52. List<Company> companies = companyRepository.findCompanyWithEmployes2(new Date(), 1l);
  53. List<Company> companies2 = companyRepository.findCompanyWithEmployes(new Date(), 1l);
  54. }
  55. }
  56.  
  57. public interface CompanyRepository extends JpaRepository<Company, Long> {
  58.  
  59. @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")
  60. List<Company> findCompanyWithEmployes2(@Param("dateee") Date dateee, @Param("id") Long id);
  61.  
  62. @Query(" SELECT c FROM Employee e LEFT JOIN FETCH e.company c WHERE e.hireDate > :dateee and e.departureDate < :dateee and c.id=:id")
  63. List<Company> findCompanyWithEmployes(@Param("dateee") Date dateee, @Param("id") Long id);
  64. }
  65.  
  66. @Entity
  67. public class Company {
  68.  
  69. @Id
  70. Long id;
  71.  
  72. String name;
  73.  
  74. @OneToMany(mappedBy = "company", cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
  75. private Set<Employee> employees;
  76.  
  77. }
  78.  
  79. @Entity
  80. public class Employee {
  81.  
  82. @Id
  83. Long id;
  84.  
  85. String name;
  86.  
  87. Date hireDate;
  88.  
  89. Date departureDate;
  90.  
  91. @ManyToOne
  92. @JoinColumn(name = "companyId", insertable = false, updatable = false)
  93. Company company;
  94.  
  95. }
  96.  
  97. spring.datasource.url:jdbc:oracle:thin:@//myServer.com:1521/TESTDB
  98. spring.datasource.username=TESTUSER
  99. spring.datasource.password=TESTUSER
  100. spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
  101. spring.jpa.hibernate.ddl-auto=none
  102. spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
  103.  
  104. spring.jpa.show-sql = true
  105. logging.level.org.springframework.data=DEBUG
  106.  
  107. @Repository
  108. public interface CompanyRepository extends JpaRepository<Company, Long> {
  109.  
  110. @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")
  111. List<Company> findCompanyWithEmployes2(@Param("dateee") Date dateee, @Param("id") Long id);
  112.  
  113. @Query(" SELECT c FROM Employee e LEFT JOIN FETCH e.company c WHERE e.hireDate > :dateee and e.departureDate < :dateee and c.id=:id")
  114. List<Company> findCompanyWithEmployes(@Param("dateee") Date dateee, @Param("id") Long id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement