异常的org.hibernate.LazyInitializationException: could not initialize proxy
程序员文章站
2022-03-02 14:37:55
...
昨天总是抛出这个异常,想想最简单的方法估计就是把fetch设置为FetchType.EAGER,可这未免也太影响了效率,在网上上尝试了几种方法人们都建议把fetch 设为 FetchType.EAGER,或者通过在web.xml中设置OpenSessionInViewFilter,结果都不凑效,在同事的指导下发现用fetch可以解决这一难题。这就是fetch的功能。我们可以把fetch与lazy="true"的关系类比为事务当中的编程式事务与声明式事务。
错误的hql语句
加入fetch以后
错误的hql语句
SELECT bioChemicalInfo FROM BioChemicalInfo AS bioChemicalInfo LEFT JOIN bioChemicalInfo.experiment AS experiment LEFT JOIN experiment.experimentProcesses experimentProcess LEFT JOIN experimentProcess.experimentProcessRecords
加入fetch以后
SELECT bioChemicalInfo FROM BioChemicalInfo AS bioChemicalInfo LEFT JOIN [color=blue]FETCH [/color]bioChemicalInfo.experiment AS experiment LEFT JOIN FETCH experiment.experimentProcesses experimentProcess LEFT JOIN FETCH experimentProcess.experimentProcessRecords
推荐阅读
-
java.lang.NoClassDefoundError:Could not initialize class sun.awt.X11GraphicsEnvironment异常
-
Dynamic Proxy的异常处理
-
Dynamic Proxy的异常处理
-
could not initialize proxy - no Session
-
解决:org.hibernate.LazyInitializationException: could not initialize proxy - no Session
-
HTTP Status 500 - Could not write content: could not initialize proxy - no Session
-
异常org.hibernate.QueryException: could not resolve property的原因
-
异常org.hibernate.QueryException: could not resolve property的原因
-
could not initialize proxy - no Session:解决懒加载(排除不需要查询显示的属性)
-
org.hibernate.LazyInitializationException: could not initialize proxy [xxxx] - no Session异常