控制session的关闭可以在web.xml中通过过滤器来实现
openSessionInView
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
事务管理 可以在application.xml中代码如下,我在业务层对事务进行统一管理。业务层在com.service包下
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- 事务属性(新功能)
propagation="REQUIRED"(默认)事务传播行为(没有事务就传,有事务就用原来的)
isolation="DEFAULT" (默认)事务隔离级别(由dbms隔)
-->
<tx:advice id="mytx">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"
isolation="DEFAULT" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="saveorupdate" propagation="REQUIRED" />
<tx:method name="*" propagation="SUPPORTS" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 织入 -->
<aop:config>
<aop:advisor advice-ref="mytx"
pointcut="execution(* com.service.*.*(..))" />
</aop:config>