鸟儿飞的专栏

生在红旗下,长在春风里~~~为实现中国四个现代化努力工作~~

用户操作
[即时聊天] [发私信] [加为好友]
鸟儿飞ID:birdme007
47725次访问,排名2320好友4人,关注者19
郑州工业大学
birdme007的文章
原创 38 篇
翻译 0 篇
转载 75 篇
评论 53 篇
鸟儿飞的公告
fanghl007@163.com
最近评论
bluehouse1985:InstallShield & InstallAnywhere 涨价前最后一次特卖!
Acresso公司主打产品installshield和installanywhere从11月1日起全面涨价!InstallShield & InstallAnywhere 涨价前最后一次特卖!仅10天!先到先得!
为庆祝最新版InstallShield 2009 &……
bluehouse1985:InstallShield 2009 升级优惠中!
为庆祝最新版InstallShield 2009上市,答谢广大新老用户的支持与厚爱,从即日起,上海世全软件(XLsoft)举办InstallShield 2009优惠活动!数量有限,售完为止!
销售热线:021-62128912/010-64616123
销售邮箱:sales@XLsoft.com.cn
zz:气体报警器
二氧化碳检测仪
可燃气体探测器
气体报警器
二氧化碳检测仪
可燃气体探测器

[url=http://www.smt16.cn]编带机[/url]
文章分类
收藏
    相册
    JAVA站点
    Gmail邮箱申请
    JavaEye
    JavaScript教程
    Java世界社区
    Matrix 与JAVA共舞
    中国Eclipse社区
    中国IT实验室
    中文JAVA技术网
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition 收藏

    新一篇: open session and Hibernate事务处理机制 | 旧一篇: Java util之常用数据类型特性盘点

    1. 错误代码:
        org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
      错误原因:
        OpenSessionInViewFilter在getSession的时候,会把获取回来的session的flush mode 设为FlushMode.NEVER。然后把该sessionFactory绑定到TransactionSynchronizationManager,使request的整个过程都使用同一个session,在请求过后再接除该sessionFactory的绑定,最后closeSessionIfNecessary根据该session是否已和transaction绑定来决定是否关闭session。在这个过程中,若HibernateTemplate 发现自当前session有不是readOnly的transaction,就会获取到FlushMode.AUTO Session,使方法拥有写权限。
      也即是,如果有不是readOnly的transaction就可以由Flush.NEVER转为Flush.AUTO,拥有insert,update,delete操作权限,如果没有transaction,并且没有另外人为地设flush model的话,则doFilter的整个过程都是Flush.NEVER。所以受transaction保护的方法有写权限,没受保护的则没有。
      参考文章:
        http://calvin.blog.javascud.org/post/46.htm
      解决办法:
        采用spring的事务声明,使方法受transaction控制
      <bean id="baseTransaction"
      class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
                abstract="true">
              <property name="transactionManager" ref="transactionManager"/>
              <property name="proxyTargetClass" value="true"/>
              <property name="transactionAttributes">
                  <props>
                      <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
                      <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
                      <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
                      <prop key="save*">PROPAGATION_REQUIRED</prop>
                      <prop key="add*">PROPAGATION_REQUIRED</prop>
                      <prop key="update*">PROPAGATION_REQUIRED</prop>
                      <prop key="remove*">PROPAGATION_REQUIRED</prop>
                  </props>
              </property>
          </bean> 
          <bean id="userService" parent="baseTransaction">
              <property name="target">
                  <bean class="com.phopesoft.security.service.impl.UserServiceImpl"/>
              </property>
          </bean>

     

    发表于 @ 2007年07月02日 16:40:00|评论(loading...)|编辑

    新一篇: open session and Hibernate事务处理机制 | 旧一篇: Java util之常用数据类型特性盘点

    评论

    #hulifang333 发表于2008-06-12 15:28:26  IP: 220.249.106.*
    我也遇到了这样的问题,但奇怪的是在xml文件中声明了事务和没声明事务都会抛这个异常,郁闷了2天一夜了,您知道为什么吗?谢谢告知!
    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © 鸟儿飞