Hibernate OpenSessionInViewFilter+;JSF中的重定向
我有使用Spring和Hibernate的JSF2.1应用程序 为了解决懒散的加载问题,我使用OpenSessionInView过滤器Hibernate OpenSessionInViewFilter+;JSF中的重定向,hibernate,spring,jsf,jsf-2,Hibernate,Spring,Jsf,Jsf 2,我有使用Spring和Hibernate的JSF2.1应用程序 为了解决懒散的加载问题,我使用OpenSessionInView过滤器 <filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filte
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
openSessionInViewFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
openSessionInViewFilter
/*
一切都很好,我的惰性类被启动,但当我使用带有重定向的导航规则时
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>fail</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
/index.xhtml
失败
/index.xhtml
我得到了org.hibernate.LazyInitializationException:
id我删除了
标记一切正常
为什么??是否因为创建了新视图?那么为什么我有新的Hibernate会话呢?
附近有工作吗
通过向浏览器返回301(或303)响应代码来实现,从而完成当前请求并关闭当前(休眠)会话
然后,浏览器向提供的URL提交一个新的请求,从而生成一个全新的(Hibernate)会话,您尚未初始化的实体不会绑定到该会话
您需要在重定向之前(如果可能的话)手动触发现有请求中的初始化,或者在重定向之后重新获取所有必要的实体