FlushMode.NEVER/MANUAL

rickey_f 2009-11-09 09:21:05
我的spring配置文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<import resource="applicationContext-km.xml"/>

<bean id="sessionFactory"
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="sessionFactory" />
</bean>


<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.rickey..*.*Dao.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.rickey..*.*DaoImpl.*(..))" />
</aop:config>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
<tx:method name="*update*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
<tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
<tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>



</beans>


调用方法:this.getHibernateTemplate().save(实体)时,发生以下异常:
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.


我想应该是spring的配置文件有误造成,但不知道问题在哪里,望各位帮忙解决一下!
...全文
290 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sangshusen_1988 2009-11-10
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 rickey_f 的回复:]
我在dao中的方法名为:addRickry(Rickry rickry )

这也有问题??
[/Quote]
当然有问题了,你增加的话肯定是进行事务操作了。但是被你设置成readonly了,你还是修改成save吧
youjianbo_han_87 2009-11-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 javaalpha 的回复:]
引用 8 楼 youjianbo_han_87 的回复:
报错很明显啊,告诉你怎么改了啊。

这个问题这么解决的很多。
[/Quote]

哈哈,这只是个权益之计,楼主去看清楚这几个参数的真正意义,才是解决办法的根本,我没有帮你细看。哈哈
JavaAlpha 2009-11-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 youjianbo_han_87 的回复:]
报错很明显啊,告诉你怎么改了啊。

  <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
            <tx:method name="*update*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
            <tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
            <tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
            <tx:method name="*" read-only="true" />
        </tx:attributes>
    </tx:advice>


把 read-only 改为 false试试。
[/Quote]

这个问题这么解决的很多。
道光2008 2009-11-10
  • 打赏
  • 举报
回复
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.
写操作不能使用,使用read-only 模式。
在程序里面设置
hibernateTemplate.setFlushMode(FlushMode.COMMIT);

youjianbo_han_87 2009-11-10
  • 打赏
  • 举报
回复
报错很明显啊,告诉你怎么改了啊。

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
<tx:method name="*update*" propagation="REQUIRED" isolation="READ_COMMITTED" rollback-for="Exception" />
<tx:method name="get*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
<tx:method name="find*" propagation="REQUIRED" isolation="DEFAULT" read-only="true" rollback-for="Exception" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>


把 read-only 改为 false试试。
lzh_me 2009-11-10
  • 打赏
  • 举报
回复
mark
yyhlove 2009-11-10
  • 打赏
  • 举报
回复
继续关注。
zl3450341 2009-11-10
  • 打赏
  • 举报
回复
<!-- 事务配置 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 查询方法只读 -->
<tx:method name="find*" propagation="REQUIRED" read-only="true"/>
<!-- 其它方法使用普通事务 -->
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>


只有查询方法才是只读
rickey_f 2009-11-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 swandragon 的回复:]
检查你的方法名
http://topic.csdn.net/u/20080605/23/d336d826-39d4-475c-b460-f4ff01f676b1.html
[/Quote]


我在dao中的方法名为:addRickry(Rickry rickry )

这也有问题??
rickey_f 2009-11-09
  • 打赏
  • 举报
回复
我在dao中的方法名为:addRickry(Rickry rickry )

这也有问题??
littlemonster 2009-11-09
  • 打赏
  • 举报
回复
恩,学习了。。
swandragon 2009-11-09
  • 打赏
  • 举报
回复

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧