Hibernate出错 - could not initialize proxy - the owning Session was closed[zz]

分析原因:
由于Spring控制的Hibernate的生命周期只针对数据层和服务层,而未管理到表现层,所以会出现the owning Session was closed的现象。针对这一点,我通过hibernate filter的方式来解决。

解决方法:
在web.xml中配置filter来解决。

 

<!-- hibernate session filter --> 
<filter> 
   
<filter-name> hibernateFilter </filter-name> 
   
<filter-class>     org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
   
</filter-class> 
</filter> 

<filter-mapping> 
   
<filter-name> hibernateFilter </filter-name> 
   
<url-pattern> *.do </url-pattern> 
</filter-mapping>

 

 

我们的系统架构是struts+spring+hibernate,struts跟spring的整合是在struts-config.xml里加了个plugin:

<plug-in
        
className="org.springframework.web.struts.ContextLoaderPlugIn">
        
<set-property property="contextConfigLocation"
         value
="classpath*:spring/**/*.xml" />
        
</plug-in>

 

在web.xml中配置hibernateFilter 后,还需要在struts-config.xml里把plugin去掉,在web.xml里加上如下代码:

 

<!--Spring ApplicationContext-->
    
<context-param>

       
<param-name>contextConfigLocation</param-name>

       
<param-value>classpath*:spring/**/*.xml</param-value>

    
</context-param>
    
    
<listener>
        
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    
</listener>

 

 

 

posted @ 2009-06-04 13:18  阿拉密斯  阅读(1202)  评论(0编辑  收藏  举报