Spring + OpenSessionInView不起作用

时间:2017-06-10 13:55:50

标签: java spring hibernate spring-mvc

我是Spring新手,想使用OpenSessionInView,所以我不必实现Filter

file web.xml

<!-- openSessionInView SpringMVC -->
<filter>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>
    </init-param>        
</filter>

<filter-mapping>
    <filter-name>OpenSessionInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<!-- FIM openSessionInView SpringMVC -->

即使将OpenSessionInView声明放在web.xml文件中,系统也会在我使用fetch=FetchType.LAZY

时返回会话错误
Exception returned
type Exception report

message org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.pedidos.entities.Representante.listUser, no session or session was closed

感谢

0 个答案:

没有答案