在进行save操作时抛出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.异常
在网上找了许久,全是千篇一律。基本上都是说在web.xml的过滤器加FlushMode,但是我这个只有Spring+Hibernate,哪来的web.xml。也有说加事务处理的,但是我加了事务,测试了无数遍,还是不行,请大神们帮忙下,谢谢,下面是我的xml配置
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- Stock business object -->
<bean id="stockBo" class="com.yiibai.stock.bo.impl.StockBoImpl" >
<property name="stockDao" ref="stockDao" />
</bean>
<bean id="stockDao" class="com.yiibai.stock.dao.impl.StockDaoImpl" >
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="save">PROPAGATION_SUPPORTS</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="dataSource" ref="dataSource" />
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="productBoProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target" ref="stockDao" />
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
下面是具体错误信息
Exception in thread "main" 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.
at org.springframework.orm.hibernate5.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1093)
at org.springframework.orm.hibernate5.HibernateTemplate.lambda$update$13(HibernateTemplate.java:658)
at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:383)
at org.springframework.orm.hibernate5.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:349)
at org.springframework.orm.hibernate5.HibernateTemplate.update(HibernateTemplate.java:657)
at org.springframework.orm.hibernate5.HibernateTemplate.update(HibernateTemplate.java:652)
at com.yiibai.stock.dao.impl.StockDaoImpl.update(StockDaoImpl.java:17)
at com.yiibai.stock.bo.impl.StockBoImpl.update(StockBoImpl.java:20)
at com.yiibai.common.App.main(App.java:28)