hibernate.enable_lazy_load_no_trans is not working

那年仲夏 提交于 2021-01-20 07:45:31

问题


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

i have added

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

into properties section

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


回答1:


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.

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

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




回答2:


Try enter the "true" like this:

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

It work for me.



来源:https://stackoverflow.com/questions/28246182/hibernate-enable-lazy-load-no-trans-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!