(详解)Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yuzongtao/article/details/40919503

昨天发现以前正常的功能报错了,错误日志如下:

报错日志:
Hibernate: select taxtypecon0_.ID as ID62_, taxtypecon0_.TAX_TYPE_NAME as TAX2_62_, taxtypecon0_.EXPRESSIONS as EXPRESSI3_62_, taxtypecon0_.CREATE_DATE as CREATE4_62_, taxtypecon0_.CREATED_BY as CREATED5_62_, taxtypecon0_.LAST_UPDATE_DATE as LAST6_62_, taxtypecon0_.LAST_UPDATED_BY as LAST7_62_, taxtypecon0_.type_kind as type8_62_, taxtypecon0_.VALID_DATE_START as VALID9_62_, taxtypecon0_.VALID_DATE_END as VALID10_62_, taxtypecon0_.IS_VALID as IS11_62_ from tb_TAXTYPE_CONFIG taxtypecon0_ where (taxtypecon0_.type_kind=1 ) order by taxtypecon0_.CREATE_DATE desc
Hibernate: select taxtypecon0_.ID as ID62_, taxtypecon0_.TAX_TYPE_NAME as TAX2_62_, taxtypecon0_.EXPRESSIONS as EXPRESSI3_62_, taxtypecon0_.CREATE_DATE as CREATE4_62_, taxtypecon0_.CREATED_BY as CREATED5_62_, taxtypecon0_.LAST_UPDATE_DATE as LAST6_62_, taxtypecon0_.LAST_UPDATED_BY as LAST7_62_, taxtypecon0_.type_kind as type8_62_, taxtypecon0_.VALID_DATE_START as VALID9_62_, taxtypecon0_.VALID_DATE_END as VALID10_62_, taxtypecon0_.IS_VALID as IS11_62_ from tb_TAXTYPE_CONFIG taxtypecon0_ where (taxtypecon0_.ID=101 )
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
    at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1186)
    at org.springframework.orm.hibernate3.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:750)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:748)
    at com.linkage.framework.pub.dao.BaseDao.saveOrUpdate(BaseDao.java:65)
    at com.linkage.budgetNew.cform.dao.impl.TaxtypeConfigDaoImpl.saveTaxtype(TaxtypeConfigDaoImpl.java:33)
    at com.linkage.budgetNew.cform.service.impl.TaxtypeConfigServiceImpl.saveTaxtype(TaxtypeConfigServiceImpl.java:24)
    at com.linkage.budgetNew.cform.service.impl.TaxtypeConfigServiceImpl$$FastClassByCGLIB$$766ec933.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
    at com.linkage.budgetNew.cform.service.impl.TaxtypeConfigServiceImpl$$EnhancerByCGLIB$$aa2803a3.saveTaxtype(<generated>)
    at com.linkage.budgetNew.cform.action.TaxTypeConfigAction.saveTaxType(TaxTypeConfigAction.java:53)
	

DEBUG调试发现在DAO层调用saveOrUpdate()方法时报错
public void saveTaxtype(TaxtypeConfig TaxtypeConfig)
{
    saveOrUpdate(TaxtypeConfig);
}

对比日志说的:

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session
 into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

知道是配置Hibernate事务管理有问题,果然发现下面这行被别人误删掉了,加上这句话就OK了。

<tx:method name="save*" rollback-for="Exception" propagation="REQUIRED"/>
没有这一行,事务管理默认走最下面的

<tx:method name="*" propagation="SUPPORTS" read-only="true" />
这样就无法进行“写操作”了:
 Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)

<!-- 事务管理 -->
	<tx:advice id="txAdvice2" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="do*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="save*" rollback-for="Exception" propagation="REQUIRED"/>
            <tx:method name="del*" propagation="REQUIRED" rollback-for="Exception" />
            <tx:method name="mod*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="ins*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="upd*" propagation="REQUIRED" rollback-for="Exception" />
			<tx:method name="invoke" propagation="REQUIRES_NEW" rollback-for="Exception" />
			<tx:method name="*" propagation="SUPPORTS" read-only="true" />
		</tx:attributes>
	</tx:advice>


阅读更多
换一批

ssh2中报Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL

09-27

在做注册和更新时就会这个错误,麻烦高手棒棒忙,谢谢rn错误信息:严重: Servlet.service() for servlet default threw exceptionrnorg.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in [color=#FF0000]read-only [/color]mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.rnrn我的applicationContext.xml是rn[code=XML]rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn org.hibernate.dialect.MySQLDialectrn rn true rn rn truern rn falsern gbkrn rn truern truern rn rn after_transactionrn rn rn rn rn rn com/jndi/test/pojo/User.hbm.xmlrn com/jndi/test/pojo/Groups.hbm.xmlrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rn++++++++++++++++++++++++++++++++++++++++++++++++++rn我的struts.xml是rn[code=XML]rnrnrnrn rn rn /all.jsprn /add.jsprn /ok.jsprn rn rn[/code]rn+++++++++++++++++++++++++++++rn我的web.xml是:rn[code=XML]rnrn rn login.jsprn rn rn rn contextConfigLocationrn rn classpath:applicationContext.xml,classpath:applicationContext-*.xmlrn rn rn rn rn rn org.springframework.web.context.ContextLoaderListenerrn rn rn rn rn org.springframework.web.context.request.RequestContextListenerrn rn rn rn rn OpenSessionInViewFilterrn rn org.springframework.orm.hibernate3.support.OpenSessionInViewFilterrn rn rn rn OpenSessionInViewFilterrn /*rn rn rn rn struts2 rn org.apache.struts2.dispatcher.FilterDispatcherrn rn rn struts2rn *.actionrn rn rn struts2rn *.jsprn rn rn struts2rn /struts/*rn rn rn struts-cleanuprn org.apache.struts2.dispatcher.ActionContextCleanUp rn rn rn rn struts-cleanuprn /*rn rn[/code]rn谢谢

Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your

02-21

action代码:rn执行这句报错rnDlybuy newDlybuy = dlybuySerive.saveReturnObject(dlybuy);rn前面一个方法也是调用的这个方法都没有问题,但是putaway()方法调用就报异常rn异常信息:rnorg.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.rn at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1175)rn at org.springframework.orm.hibernate3.HibernateTemplate$23.doInHibernate(HibernateTemplate.java:816)rn at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)rn at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)rn at org.springframework.orm.hibernate3.HibernateTemplate.merge(HibernateTemplate.java:813)rn at com.dx.business.salesManagement.dao.DlybuyDao.saveReturnObject(DlybuyDao.java:18)rn at com.dx.business.salesManagement.service.DlybuyService.saveReturnObject(DlybuyService.java:45)rn at com.dx.business.salesManagement.action.DlyndxAction.putaway(DlyndxAction.java:487)rn at com.dx.business.salesManagement.action.DlyndxAction.putaway(DlyndxAction.java:356)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rnspring配置文件:rnrn PROPAGATION_REQUIREDrn PROPAGATION_SUPPORTSrn PROPAGATION_SUPPORTSrn PROPAGATION_SUPPORTSrn PROPAGATION_SUPPORTSrn PROPAGATION_NEVER,readOnlyrn rn我把PROPAGATION_NEVER,readOnly这句删除了还是会报同样的错

Write operations are not allowed in read-only mod......

12-06

今天在做spring2.x+struts2.0+hibernate3.x的项目时候,在执行更新操作的时候,出现的问题,大家帮助给看一下:rnrnorg.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.rn at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1095)rn at org.springframework.orm.hibernate3.HibernateTemplate$14.doInHibernate(HibernateTemplate.java:656)rn at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)rn at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:654)rn at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:650)rn at com.dacc.dcp.dao.impl.DPourRecordDAO.saveOrUpdateDPourRecord(DPourRecordDAO.java:61)rn at com.dacc.pp.service.impl.DHeatRecordService.saveOrUpdateDPourRecord(DHeatRecordService.java:29)rn at com.dacc.pp.action.Pouring_updateWheelAction.updateWheelInfo(Pouring_updateWheelAction.java:52)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn rn----------------------------------------------------------------------------------------rnweb.xmlrnrn rn contextConfigLocation rn /WEB-INF/classes/bean.xml rn rn rn rn org.springframework.web.context.ContextLoaderListener rn rn rn rn lazyLoadingFilter rn org.springframework.orm.hibernate3.support.OpenSessionInViewFilter rn rn singleSessionrn truern rn rn rn struts2rn org.apache.struts2.dispatcher.FilterDispatcherrn rn rn lazyLoadingFilterrn *.actionrn rn rn struts2rn /*rn rn rn index.jsprn rnrnrnrn----------------------------------------------------------------------------------------rnspring 配置文件rnrnrn rn rn rn rn rn rn rn rn rn rn rn PROPAGATION_REQUIRED,readOnlyrn PROPAGATION_REQUIREDrn PROPAGATION_REQUIREDrn rn rn rn rn rn rn rn rn DHeatRecordServiceImplrn DPourRecordServiceImplrn rn rn rn rn rn rn transactionInterceptorrn rn rn rn rn rn rn ......rnrn---------------------------------------------------------------------------------rnDao 层rnrn public int saveOrUpdateDPourRecord(DPourRecord vo)rn log.debug("save or update object");rn rn DPourRecord bean = findDPourRecordByWheelCode(vo.getWheelCode());rn System.out.println(bean.getPourId());rn bean.setWheelCode(vo.getWheelCode());rn bean.setCopeNo(vo.getCopeNo());rn bean.setCopeScrap(vo.getCopeScrap());rn bean.setTestCode(vo.getTestCode());rn bean.setDragScrap(vo.getDragScrap());rn bean.setSpecialUltra(vo.getSpecialUltra());rn bean.setStates(vo.getStates());rn rn try rn getHibernateTemplate().update(bean);rn getHibernateTemplate().flush();rnrn catch (RuntimeException e) rn log.error("save or update object failed!");rn e.printStackTrace();rnrn rn rn return 0;rn rnrnrn------rnrn//通过车轮号查找对象rn public DPourRecord findDPourRecordByWheelCode(String wheelCode)rn log.debug("find id by wheelCode!");rn List paramsList = new ArrayList();rn List objectList = new ArrayList();rn paramsList.add(wheelCode);rn System.out.println(wheelCode);rn String strSql = "From DPourRecord where wheel_code =?";rn DPourRecord dpr;rn try rn dpr =(DPourRecord) getHibernateTemplate().find(strSql, paramsList.toArray()).get(0);rn rn catch (RuntimeException e) rn log.error("find id by wheel_code is failed!");rn throw e;rn rn return dpr;rn rnrn---------------------rn请大家帮助给看一下,项目着急在用!,在网上查的说去掉spring 配置文件不必要的readyOnly ,还有说修改web.xml 文件,我照做,还是没解决问题

急!!!ssh开发中spring 事务管理出现Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL)

03-30

网上说要在spring中设置对openseesioninviewfilter的管理,我设了可是为什么还是不行呢。rn先把applicationContext发给大家看看 帮帮忙!!rn[code=Java]rnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn org.hibernate.dialect.Oracle9Dialectrn rn truern rn rn rn rn /com/neusoft/crm/model/Employee.hbm.xmlrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn[/code]rn下面是struts.xmlrn[code=Java]rnrnrnrnrn rn rn rn rn list.actionrn rn rn rn list.jsprn rn rn rn list.actionrn rn rn[/code]rnrn还有web.xmlrn[code=Java]rnrnrnrn rn rn rn rn list.actionrn rn rn rn list.jsprn rn rn rn list.actionrn rn rn[/code]rnJSP页面add.jsprn[code=Java]<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>rn<%@ taglib uri="/struts-tags" prefix="s" %>rnrnrn rn rn rn add pagern rn rn rn rn rn rn rnrn rn rn rn 请输入信息: rnrn rnrnrnrnrn rnrn[/code]rn出错信息:rnorg.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.rn org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1095)rn org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:634)rn org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)rn org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:632)rn com.neusoft.crm.dao.hibernate.EmployeeDaoHibernate.add(EmployeeDaoHibernate.java:15)rn com.neusoft.service.impl.EmployeeManagerImpl.addEmployee(EmployeeManagerImpl.java:16)rn com.neusoft.crm.action.EmployeeAction.add(EmployeeAction.java:38)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn java.lang.reflect.Method.invoke(Method.java:597)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)rn老是有这个错误 困惑好几天了 大家看看怎么回事 谢谢了

我已经配置了事物为什么还是报错Write operations are not allowed in read-only mode (FlushMode.MAN

10-20

用户登陆,插入日志信息rn[code=java]public String execute() throws Exception rn try rn HttpServletRequest request = ServletActionContext.getRequest();rn Loginlog loginlog = new Loginlog(user.getUname(), new Timestamp(new Date().getTime()), request.getRemoteAddr());rn User users = this.userService.userLogin(user, loginlog);rn ServletContext servletContext = ServletActionContext.getServletContext();rn HttpSession existSession = (HttpSession) servletContext.getAttribute(this.user.getUname());rn if (existSession != null) rn existSession.invalidate();rn servletContext.removeAttribute(this.user.getUname());rn rn HttpSession session = request.getSession();rn session.setAttribute(Constant.LOGIN_USER, users);rn servletContext.setAttribute(this.user.getUname(), session);rn catch (UserNotFoundException e) rn this.msg = e.getMessage();rn return INPUT;rn rn return SUCCESS;rn [/code]rnrn[color=#FF0000][b][size=16px]service[/size][/b][/color]rn[code=java]@Overridern public User userLogin(User user, Loginlog loginlog) rn User u = this.userDao.get(user.getUname());rn if (u == null || u.getUname().length() <= 0) rn throw new UserNotFoundException(Constant.USER_LOGIN_KEY_UNAME);rn else rn if (!u.getPwd().equals(user.getPwd())) rn throw new UserNotFoundException(Constant.USER_LOGIN_KEY_PWD);rn rn rn this.init(u);rn return u;rn [/code]rnapplicationcontext。xmlrn[code=java]rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn [/code]rn切面aspectrn[code=java]public class UserLoginlogAspect extends BaseDaoImpl implements MethodInterceptor rnrn @Overridern public Object invoke(MethodInvocation arg0) throws Throwable rn User user = (User) arg0.proceed();rn Object[] arr = arg0.getArguments();rn this.addLoginlog((Loginlog) arr[1]);rn return user;rn rnrn /**rn * 插入用户登陆日志信息rn * @param loginlogrn */rn private void addLoginlog(Loginlog loginlog) rn this.getHibernateTemplate().save(loginlog);rn rn[/code]rn[b][color=#FF0000][size=24px]就是这个切面插入日志报的错[/size][/color][/b]rn切面配置aspectrn[code=java] rn rn rn rn rn rn rn rn rn rn [/code]

没有更多推荐了,返回首页