Property or field ‘XXX‘ cannot be found on null
程序员文章站
2022-07-15 16:16:19
...
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: "name" (template: "admin/types-input" - line 32, col 71)
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "name" (template: "admin/types-input" - line 32, col 71)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1021E: A problem occurred whilst attempting to access the property 'name': 'Unable to access property 'name' through getter method'
org.hibernate.LazyInitializationException: could not initialize proxy [com.athome.blog.pojo.Type#15] - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:170) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:310) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.intercept(ByteBuddyInterceptor.java:45) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
at org.hibernate.proxy.ProxyConfiguration$InterceptorDispatcher.intercept(ProxyConfiguration.java:95) ~[hibernate-core-5.4.18.Final.jar:5.4.18.Final]
已有开发环境如下
Windows平台
jdk1.8、maven已配置
开发工具:Intellij IDEA
在使用springboot 1.XX时,JpaRepository支持findOne(ID)方法
public Type getType(Long id) {
return typeRepository.findOne(id);
}
或者
public Type getType(Long id) {
return typeRepository.getOne(id);
}
但是在springboot 2.XX时findOne()方法不能这样简单使用,于是使用
findById()
public Type getType(Long id) {
Optional<Type> type = typeRepository.findById(id);
return type.get();
}
完美解决
推荐阅读
-
npm ERR! Cannot read property 'path' of null
-
js报错 Cannot read property 'getAttribute' of null
-
JavaScript Uncaught TypeError: Cannot read property 'value' of null
-
Property or field ‘XXX‘ cannot be found on null
-
org.springframework.data.mapping.PropertyReferenceException: No property xxx found for type xxx
-
使用spring-data-jpa进行count时报错No property count found for type xxx的解决方案
-
No property name found for type XXX解决
-
Spring Data: no property xxx found for type xxxx
-
JPA踩坑:No property xxx found for type xxx
-
Ambiguous mapping found. Cannot map 'xxx' bean method