Write operations are not allowed in read-only mode
编程技术  /  houtizong 发布于 3年前   67
<!-- 配置事务拦截器--> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <!-- 事务拦截器bean需要依赖注入一个事务管理器 --> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <!-- 下面定义事务传播属性--> <props> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="save*">PROPAGATION_REQUIRED</prop> <prop key="add*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="edit*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="write">PROPAGATION_REQUIRED,readOnly</prop> </props> </property> </bean>
<filter> <filter-name>openSessionInViewFilter</filter-name> <!-- filter-class原来为org.springframework.orm.hibernate3.support.OpenSessionInViewFilter--> <filter-class>com.ao.web.util.OpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter>
package com.ao.web.util;import org.hibernate.FlushMode;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.springframework.dao.DataAccessResourceFailureException;import org.springframework.orm.hibernate3.SessionFactoryUtils;/** * @author Administrator * */public class OpenSessionInViewFilter extends org.springframework.orm.hibernate3.support.OpenSessionInViewFilter {protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {Session session = SessionFactoryUtils.getSession(sessionFactory, true); FlushMode flushMode = session.getFlushMode(); if (flushMode != null) { session.setFlushMode(FlushMode.AUTO);//原来为 session.setFlushMode(flushMode); } return session;}protected void closeSession(Session session, SessionFactory sessionFactory) {session.flush(); super.closeSession(session,sessionFactory); }}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接