hibernate.enable_lazy_load_no_trans无法正常工作 [英] hibernate.enable_lazy_load_no_trans is not working

查看:94
本文介绍了hibernate.enable_lazy_load_no_trans无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JPA2.1和hibernate 4.3.8,并且已将presistence.xml配置为允许延迟加载

I'm using JPA2.1 and hibernate 4.3.8 and i have configured the presistence.xml to allow lazy loading

我已添加

<property name="hibernate.enable_lazy_load_no_trans" value="true" />

进入属性部分

但是我仍然收到LazyInitializtionException,这是什么问题?

but i'm still getting LazyInitializtionException, what is the problem ?

推荐答案

hibernate.enable_lazy_load_no_trans 反模式,并且您永远不要使用它,因为从初始持久性上下文之外获取的每个惰性关联都需要数据库连接,这将对基础事务日志和JDBC连接池造成压力.

The hibernate.enable_lazy_load_no_trans is an anti-pattern and you should never use it because a database connection is needed for every lazy association that is fetched outside of the initial Persistence Context, and that's going to put pressure on the underlying transaction log and the JDBC connection pool.

更多, hibernate.enable_lazy_load_no_trans 容易出现N + 1个查询问题.

More, the hibernate.enable_lazy_load_no_trans is prone to N+1 query issues.

有时候,您甚至不需要实体,而DTO投影甚至更好.

Sometimes, you don't even need entities, and a DTO projection is even better.

这篇关于hibernate.enable_lazy_load_no_trans无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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