(详解)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

04-17

[size=16px]前言:[/size][color=#FF0000][/color]求帮助 被这个错弄崩溃了。很多人都崩溃了!因为这个错明明没有错!求大神rn具体报错:[color=#FF0000]严重: Servlet.service() for servlet [ji543box] in context with path [/springMVC] threw exception [Request processing failed; nested exception is org.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.] with root causernorg.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$12.doInHibernate(HibernateTemplate.java:685)rn at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:1)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.save(HibernateTemplate.java:683)rn at sen.shu.wu.dao.BinfoDao.add(BinfoDao.java:22)rn at sen.shu.wu.service.LoveService.findAll(LoveService.java:52)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)[/color]rnrnrn报这个错 你可能会想看我的spring事务的配置:rn[code=java] rnrn rn rn rn rn rn rn rn rn rn rn [/code]rn[code=java]@Repository("infoDao")rnpublic class BinfoDao extends HibernateDaoSupport implements IbinfoDao rn @Resourcern public void setSuperSessionFactory(SessionFactory sessionFactory) rn this.setSessionFactory(sessionFactory);rn rn rn rn @Overridern public void add(Binfo info) rn [color=#FF0000] this.getHibernateTemplate().save(info);[/color]这是22行 这里报错rn rn rn @Overridern public void update(Binfo info) rn this.getHibernateTemplate().update(info);rn rnrn @Overridern public void delete(int bid) rn Binfo info = this.load(bid);rn this.getHibernateTemplate().delete(info);rn rn rn @Overridern public Binfo load(int bid) rn return this.getHibernateTemplate().load(Binfo.class, bid);rn rn rn rn[/code]rnrnrnrnrn这个表的model:rn[code=java]rn@Entityrn@Table(name="info")rnpublic class Binfo rn private int bid;rn private String openid;rn private Boolean bsex;rn private Boolean bbutton;rn rn rn rn @GeneratedValuern @Idrn public int getBid() rn return bid;rn rn public void setBid(int bid) rn this.bid = bid;rn rn public String getOpenid() rn return openid;rn rn public void setOpenid(String openid) rn this.openid = openid;rn rn public Boolean getBsex() rn return bsex;rn rn public void setBsex(Boolean bsex) rn this.bsex = bsex;rn rn public Boolean getBbutton() rn return bbutton;rn rn public void setBbutton(Boolean bbutton) rn this.bbutton = bbutton;rn rn rn rn rnrn[/code]rnrn最郁闷的是:这个项目已经完成大量的功能了,在那些功能里面有大量的DAO方法 里面的add save 都是一样的 就是操作的表不一样 但是都不会报错! 论坛

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] 论坛

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