欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

【记录】异常:org.hibernate.LazyInitializationException: could not initialize proxy - no Session

程序员文章站 2022-04-18 22:05:31
...

  【转载自https://blog.csdn.net/u010167086/article/details/17029831

    将hibernate的抓起策略改为join。也就是是left join fetch或inner join fetch语法。就是在<many-to-one../>中配

置lazy="false" fetch="join"即可。

<many-to-one name="paint" class="com.model.Paint" fetch="select">
    <column name="paintid" not-null="true" />
</many-to-one>

修改为

<many-to-one name="paint" class="com.model.Paint" lazy="false" fetch="join">
    <column name="paintid" not-null="true" />
</many-to-one>