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.
以下是我service层的save方法:
public void bcdsave(Depart depart) {
// TODO Auto-generated method stub
this.depart.savedepartdao(depart);
}//也不知道为啥取这个名字,命名不规范啊!!!
以下是我的AOP事务配置:<tx:advice id="tx" >
<tx:attributes>
<!-- 注入事务策略 -->
<tx:method name="save*" read-only="false" />
<tx:method name="update*"
read-only="false"/>
<tx:method name="delete*"
read-only="false"/>
<!--
除了上述三种情况以外的情况
-->
<tx:method name="*"
read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 配置aop切点 -->
<aop:config proxy-target-class="true" >
<!-- 配置AOp切点策略 -->
<aop:pointcut
expression="execution(* com.ssh.service.iml.*.*(..))"
id="perform"/>
<aop:advisor advice-ref="tx" pointcut-ref="perform"/>
</aop:config>
经检查我的save方法明明已经read-only="false"了,但是却还是报错,后来再看发现我的bcdsave方法应该属于其他方法,而其他方法的事务配置是: read-only="true",终于恍然大悟,
改正如下:
1: <tx:method name="*" read-only="false"/>,其他方法也改成ead-only="false",
或者:
2:规范命名:把bcdsave改成:savestudent();