Spring-data-jpa 集成Hibernate时延迟加载问题
来源:互联网 发布:安卓程序员的前景 编辑:程序博客网 时间:2024/06/08 16:25
@GetMapping("/teachers/{id}") @Timed public ResponseEntity<Teacher> getTeacher(@PathVariable Long id) { log.debug("REST request to get Teacher : {}", id); Teacher teacher = teacherRepository.findOne(SecurityUtils.getCurrentUserId()); teacher.getAddresses().size(); --------此处代码 return ResponseUtil.wrapOrNotFound(Optional.ofNullable(teacher)); }
当在OneToMany关系中手动触发延迟加载对象时出以下错误
2017-09-13 23:33:51.859 ERROR 5392 --- [ XNIO-3 task-1] com.zhile.aop.logging.LoggingAspect : Exception in com.zhile.web.rest.TeacherResource.getTeacher() with cause = 'NULL' and exception = 'failed to lazily initialize a collection of role: com.zhile.domain.Teacher.addresses, could not initialize proxy - no Session'org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.zhile.domain.Teacher.addresses, could not initialize proxy - no Session at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:582) at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:201) at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:145) at org.hibernate.collection.internal.PersistentSet.size(PersistentSet.java:143) at com.zhile.web.rest.TeacherResource.getTeacher(TeacherResource.java:111) at com.zhile.web.rest.TeacherResource$$FastClassBySpringCGLIB$$1bff0b37.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) at com.zhile.aop.logging.LoggingAspect.logAround(LoggingAspect.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at com.ryantenney.metrics.spring.TimedMethodInterceptor.invoke(TimedMethodInterceptor.java:48) at com.ryantenney.metrics.spring.TimedMethodInterceptor.invoke(TimedMethodInterceptor.java:34)
这是由于没有配置在视图打开延迟加载特性所置,在SpringBoot的项目中通过以下配置设置:
jpa: open-in-view: true --------此处配置 database-platform: org.hibernate.dialect.MySQL5InnoDBDialect database: MYSQL show-sql: true properties: hibernate.id.new_generator_mappings: true hibernate.cache.use_second_level_cache: true hibernate.cache.use_query_cache: false hibernate.generate_statistics: true
阅读全文
0 0
- Spring-data-jpa 集成Hibernate时延迟加载问题
- hibernate+spring延迟加载问题
- spring jpa 延迟加载
- 解决Spring Data JPA延迟加载no session错误
- Spring Data 系列(二) Spring+JPA入门(集成Hibernate)
- spring data jpa 懒加载问题
- Spring Data JPA的懒加载问题
- 解决spring+springMVC+Hibernate+spring-data-jpa懒加载No session问题
- Spring集成JPA(Hibernate)
- Spring+hibernate延迟加载
- spring boot集成data-jpa
- springboot集成spring-data-jpa
- hibernate延迟加载问题
- Hibernate延迟加载问题
- Hibernate延迟加载问题
- Hibernate延迟加载问题
- spring data Jpa hibernate实现
- Spring与JPA(Hibernate)集成
- mybatis添加数据返回主键
- 欢迎使用CSDN-markdown编辑器
- Apache开启压缩功能。。
- 选择视频直播SDK的4项技术指标,5项基本能力
- SSRF漏洞的挖掘经验
- Spring-data-jpa 集成Hibernate时延迟加载问题
- SQL中的聚合函数使用总结
- python邮件发送给多人时,只有第一个人能收到的问题
- jsonp协议原理深度解析
- Letter c语言-Combinations of a Phone Number
- UGUI-仿照NGUI的事件监听机制
- 使用线性分类模型从事良/恶性肿瘤预测任务
- 剑指Offer--8.跳台阶
- Eclipse配置tomcat