hibernate懒加载导致session关闭后无法在view层得到关联数据

在controller中查询出了一个数据,数据关联了另外一个对象,在页面中用A.GETB().GETXXX()的方式的时候就会报错,因为是懒加载,默认的session已经关闭了。
解决方案:在web.xml配置文件中加入以下内容

<filter>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

.

猜你喜欢

转载自blog.csdn.net/wang037195/article/details/82758234
今日推荐