org.hibernate.LazyInitializationException:无法初始化代理 - 无会话 [英] org.hibernate.LazyInitializationException: could not initialize proxy - no Session

查看:106
本文介绍了org.hibernate.LazyInitializationException:无法初始化代理 - 无会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个物理服务器,我的Web应用程序由负载平衡器管理。我总是得到 -



org.hibernate.LazyInitializationException:无法初始化代理 - 无会话



当其中一个服务器被击中,而另一个服务器运行顺利而没有任何问题。我有一个由应用程序启用和管理的本地托管缓存存储区。只有在尝试从一个表中访问一个特定列时,才会发生此异常。无论哪个服务器被击中,其余的操作都能正常工作。



使lazy = false将成为性能问题,因为该表上的行数相当大。顺便说一下,我们在会话中使用get(object)而不是load(object)。

解决方案

从标签中提供的,我推断你使用Spring框架遇到这个问题。在使用Spring数据 org.springframework.data.jpa.repository.JpaRepository 时,我碰到相同的 LazyInitializationException / p>

我通过注释间接使用Hibernate从 @Transactional 从数据库检索数据的方法来解决问题。 / p>

I have 2 physical servers which my web application hits managed by load balancers. I always get -

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

when one of the servers are hit while the other one runs smoothly without any problems. I have a local managed cache store enabled and managed by the application. This exception happens only while trying to access one particular column from one table. The rest of the operations work absolutely fine regardless of which server is hit.

Making lazy=false will become a performance issue because the number of rows on that table is quite large. And by the way, we are using get(object) on session instead of load(object).

解决方案

From the tags you provided, I deduce you ran into this problem using Spring Framework. I ran into the same LazyInitializationException while using a Spring Data org.springframework.data.jpa.repository.JpaRepository.

I solved the problem by annotating the method which indirectly uses Hibernate to retrieve data from the database with @Transactional.

这篇关于org.hibernate.LazyInitializationException:无法初始化代理 - 无会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆