我的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' er from transaction definition.
我想应该是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' er from transaction definition.
我想应该是spring的配置文件有误造成,但不知道问题在哪里,望各位帮忙解决一下!
解决方案 »
- 疯掉了,com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:问题。
- 我安装的Myeclipse为什么不能新建Web project?除了Java Project别的点了都没反应。
- 如何用同一个变量去接收jsp页面提交form传过来的字符串和servlet中request传过来的字符串
- commons-fileupload上传数据库有的文件可以,有的文件不可以
- java 部分乱码问题
- 用最简单的话来描述spring的工作思路
- hibernate懒加载问题
- tomcat5+jdk1.5 安装完后测试程序问题?
- 部署MessageDrivenBean报错,大家帮我看看是哪儿不对,谢谢了
- 精通EJB第二版的第一个例子居然有四处错误,恨~~~~~~~~~~~~~~~~~
- 那里可以下载myeclipse插件
- Hibernate HQL 语法问题
http://topic.csdn.net/u/20080605/23/d336d826-39d4-475c-b460-f4ff01f676b1.html
<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试试。
写操作不能使用,使用read-only 模式。
在程序里面设置
hibernateTemplate.setFlushMode(FlushMode.COMMIT);
<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>只有查询方法才是只读