尝试Spring配置Open Session in View, 但是还是报no session or session was closed,可能会是什么原因?配置Open Session in View有哪些注意事项?谢谢!
web.xml配置片段
<filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>hibernateSessionFactory</param-value> </init-param> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
Spring hibernate配置片段:
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml" /> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="hibernateSessionFactory" /> </property> </bean> <aop:config> <aop:advisor pointcut="execution(* *..PersonDAOHibImpl.*(..))" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="insert*" rollback-for="java.sql.SQLException" /> <tx:method name="update*" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice>
一般都都是这样的。。。
哪有你那有控制的
看到你这 execution(* ..PersonDAOHibImpl.(..))
aop控制事务是用来控制大的services层的,不是控制小的Dao
filter是应该在struts的filter之前
我觉得是你的txAdvice 有问题,没有指定事务处理方式
还有也有可能是filter的顺序问题
最后你这个 * 竟然用read-only 想不通,难道插入的时候这里会是对的!