方法一:在web.xml配置延迟关闭session的过滤器
<!-- 延迟关闭session OpenSessionInViewFilter 的顺序位于struts2过滤之上 否则延迟关闭session不起作用 -->
<filter>
<filter-name>opensession</filter-name>
<filter-class>
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>opensession</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 启动struts的配置 -->
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
方法二:<many-to-one> 的<set>
中设置 lazy=”false”
设置lazy=”false”攻克了大部分的延时载入问题。可是同一时候也减少了系统的性能,应避免使用此方法。