Springboot 之JPA查询报错
在 CatDao中添加自定义查询方法后,启动报错
1 2019-06-11 11:06:13.874 INFO 14700 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.3.7.Final}
2 2019-06-11 11:06:13.890 INFO 14700 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
3 2019-06-11 11:06:16.270 INFO 14700 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
4 2019-06-11 11:06:17.403 INFO 14700 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
5 2019-06-11 11:06:23.144 INFO 14700 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
6 2019-06-11 11:06:23.318 INFO 14700 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
7 2019-06-11 11:06:25.815 WARN 14700 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
8 2019-06-11 11:06:25.816 INFO 14700 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
9 2019-06-11 11:06:25.842 INFO 14700 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
10 2019-06-11 11:06:25.855 INFO 14700 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
11 2019-06-11 11:06:25.858 INFO 14700 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
12 2019-06-11 11:06:26.021 INFO 14700 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
13
14 Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
15 2019-06-11 11:06:26.228 ERROR 14700 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
16
17 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
18 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:324) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
19 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1395) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
20 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
21 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
22 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
23 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
24 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
25 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
26 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
27 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
28 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
29 at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
30 at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
31 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
32 at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
33 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
34 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
35 at com.SpringBootHelloApplication.main(SpringBootHelloApplication.java:16) [classes/:na]
36 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
37 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
38 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
39 at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
40 at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.3.RELEASE.jar:2.1.3.RELEASE]
41 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
42 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:324) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
43 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1395) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
44 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
45 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
46 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
47 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
48 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
49 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
50 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeanByName(AbstractAutowireCapableBeanFactory.java:452) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
51 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:526) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
52 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
53 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:636) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
54 at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
55 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
56 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
57 ... 22 common frames omitted
58 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'catDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
59 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1762) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
60 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
61 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
62 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
63 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
64 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
65 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
66 at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
67 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1247) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
68 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
69 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:520) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
70 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
71 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:636) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
72 at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
73 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
74 at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
75 ... 36 common frames omitted
76 Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.demo.dao.CatDao.findByCatName(java.lang.String)! Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
77 at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:82) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
78 at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
79 at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:208) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
80 at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
81 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:566) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
82 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
83 at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_121]
84 at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_121]
85 at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1049) ~[na:1.8.0_121]
86 at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_121]
87 at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_121]
88 at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_121]
89 at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_121]
90 at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_121]
91 at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_121]
92 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:561) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
93 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:551) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
94 at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_121]
95 at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:551) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
96 at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:324) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
97 at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
98 at org.springframework.data.util.Lazy.getNullable(Lazy.java:211) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
99 at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
100 at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
101 at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:119) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
102 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1821) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
103 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
104 ... 51 common frames omitted
105 Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [catName] on this ManagedType [com.demo.bean.Cat]
106 at org.hibernate.metamodel.internal.AbstractManagedType.checkNotNull(AbstractManagedType.java:128) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
107 at org.hibernate.metamodel.internal.AbstractManagedType.getAttribute(AbstractManagedType.java:113) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
108 at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:593) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
109 at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:577) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
110 at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.getTypedPath(JpaQueryCreator.java:379) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
111 at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:302) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
112 at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:207) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
113 at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:120) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
114 at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:57) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
115 at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:119) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
116 at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:95) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
117 at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:81) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]
118 at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:145) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
119 at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$CountQueryPreparer.<init>(PartTreeJpaQuery.java:268) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
120 at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:77) ~[spring-data-jpa-2.1.5.RELEASE.jar:2.1.5.RELEASE]
121 ... 77 common frames omitted
122
123
124 Process finished with exit code 0
1.controller层
@RestController
@RequestMapping("/cat")
public class CatController {
@Resource
private CatService catService;
@GetMapping(value = "/findByCatName")
public List<Cat> findByCatName(String catName){
return catService.findByCatName(catName);
}
}
2.service层
@Service
public class CatService {
@Resource
private CatDao catRepository; public List<Cat> findByCatName(String catName){
return catRepository.findByCatName(catName);
}
}
3.dao层
public interface CatDao extends JpaRepository<Cat,Integer> {
//根据名称查询
List<Cat> findByCatName(String catName);
}
这样看着代码是没什么问题,而且之前在启动项目的时候,我可以通过代码生成数据库表了,所以就很自然的认为,实体是没有问题的;
但是在网上查了很多资料都是说dao层的字段名称和实体的不一致的问题,所以我就把注意力放在dao层上面去查问题,就这样查了好久,依然觉得代码没问题(很无奈啊....)
后来实在没有办法了就又去检查实体字段名称的定义,终于找到问题了,是因为字段的定义不符合规范,虽然之前已经可以通过实体生成表结构,但是在使用查询的时候,不知道为
什么还是注入不了(这个目前还没有搞清楚),最后把正确的实体贴出来,以来警醒自己吧
之前定义的变量名称是:CatAge/CatName
@Entity
public class Cat {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private int id ;//主键 private String catName;//姓名 private int catAge; //年龄 public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} public String getCatName() {
return catName;
} public void setCatName(String catName) {
this.catName = catName;
} public int getCatAge() {
return catAge;
} public void setCatAge(int catAge) {
this.catAge = catAge;
}
}
总结:
这次的错误主要是在创建实体的时候,变量的命名不规范造成的,所以简单总结下java的常用的几个命名规则:
1.包:所有包的命名必须采用小写英文字母;
2.类:采用驼峰命名法,类名的首字母必须采用大写的形式,如果类名为多个单词组合的话,那么每个字母的首字母必须采用大写,eg:CatDao.java;
3. 方法:采用驼峰命名法,首字母以小写开头,每个单词首字母大写(第一个单词除外);
4.变量:首字母以小写开头,每个单词首字母大写(第一个单词除外);
Springboot 之JPA查询报错的更多相关文章
- Jpa自定义查询报错(Failed to convert from type [java.lang.Object[]] to type)
Jpa自定义查询报错 问题背景 今天遇到一个奇怪的报错"Failed to convert from type [java.lang.Object[]] to type",这个报错 ...
- sqli注入--利用information_schema配合双查询报错注入
目录 sqli-labs 5.6双查询报错注入通关 0x01 获取目标库名 0x02 获取库中表的数量 0x03 获取库中表名 0x04 获取目标表中的列数 0x05 获取目标表的列名 0x06 从列 ...
- sql注入--双查询报错注入原理探索
目录 双查询报错注入原理探索 part 1 场景复现 part 2 形成原因 part 3 报错原理 part 4 探索小结 双查询报错注入原理探索 上一篇讲了双查询报错查询注入,后又参考了一些博客, ...
- sql注入--双查询报错注入
sql注入--双查询报错注入 背景:在sqli-labs第五关时,即使sql语句构造成功页面也没有回显出我们需要的信息,看到了有使用双查询操作造成报错的方式获得数据库信息,于是研究了一下双查询的报错原 ...
- 新建SpringBoot项目运行页面报错Whitelabel Error Page This application has no explicit mapping for /error, so yo
新建SpringBoot项目运行页面报错Whitelabel Error Page This application has no explicit mapping for /error, so yo ...
- springboot 启动的时候报错 Error creating bean with name 'solrClient'
springboot 启动的时候报错: org.springframework.beans.factory.BeanCreationException: Error creating bean wit ...
- MySQL查询报错 ERROR: No query specified
今天1网友,查询报错ERROR: No query specified,随后它发来截图. root case:查询语法错误 \G后面不能再加分号;,由于\G在功能上等同于;,假设加了分号,那么就是;; ...
- 【mybatis】【mysql】mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
mybatis查询mysql,group by分组查询报错:Expression #1 of SELECT list is not in GROUP BY clause and contains no ...
- 【Elasticsearch】ES中时间查询报错:Caused by: ElasticsearchParseException[failed to parse date field [Sun Dec 31 16:00:00 UTC 2017] with format [yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis]];
ES中时间查询报错:Caused by: ElasticsearchParseException[failed to parse date field [Sun Dec 31 16:00:00 UTC ...
- 关于springboot 连接mysql 数据库报错问题
springboot连接MySQL运行报错: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more ...
随机推荐
- Typora - typora主题样式
主题名称:github_harley.css(随便命名) 效果:Mac风格的代码块.更舒适的引用块风格. css harley01 /* 代码块主题 */ /* 顶部 */ .md-fences { ...
- PHP开发技巧:如何实现数据过滤功能
输入过滤 输出过滤 1.输入过滤 1.1前端验证 JavaScript的方式,正则等,(略) 1.2后端验证 1.2.1 使用filter_var函数 PHP提供了filter_var函数用于过滤和验 ...
- c# virtual 关键字 虚方法
1.简单的说,虚方法就是可以被子类重写的方法,如果子类重写了虚方法,那么运行时将使用重写后的逻辑,如果没有重写,则使用父类中虚方法的逻辑 class Program { static void Mai ...
- @SpringBootApplication自动配置原理
@EnableAutoConfiguration 是核心,他会调用一个@Import注解.我们已知Import自动配置得实现是通过创建ImportSelector 接口的实现类并重写里面selectI ...
- minikube搭建Kubernetes环境
前言 Kubernetes 一般都运行在大规模的计算集群上,管理很严格,Kubernetes 充分考虑到了这方面的需求,提供了一些快速搭建 Kubernetes 环境的工具. minikube 它是一 ...
- MongoDB 简单介绍
MongoDB介绍 疑问 解答 什么是 MongoDB 一个以 JSON 为数据模型的文档数据库 为什么叫文档数据库? 文档来自于 "JSON Document",并非我们一般理解 ...
- C++判断文本编码
#include <iostream> #include <fstream> #include <string> #include <sstream> ...
- Delphi让网页只允许在WebBrowser里面打开
[添加组件] 添加 Internet->WebBrowser //显示网页 [添加事件] 鼠标点击WebBrowser组件,在Events事件选项框中找到. OnNewWindows2,OnSt ...
- games101 作业4提高部分
games101 作业4提高部分 作业四中,我们按照实验步骤完成bazier曲线之后,得到的结果有一定的锯齿感: 然后pdf中给出的思路是: 对于一个曲线上的点,不只把它对应于一个像素,你需要根据到像 ...
- BUUCTF---unencode
1.题目 2.知识 UUENCODE是将二进制文件转换为文本文件的过程,转换后的文件可以通过纯文本e-mail进行传输,在接收方对该文件进行uudecode,即将其转换为初始的二进制文件. 3.解题 ...