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
根据异常提示可以判断,“只读”,说明当前方法并没有写入和修改的权限,
debug调试的时候会抛出反射包 java.lang.reflect 下的InvocationTargetException 异常,这个异常会
误导,其次这个异常涉及的太广泛,不易查找错误
解决办法:
需要在spring的配置文件中将事物只读设置为false或者涉及的方法定为"PROPAGATION_SUPPORTS"。
如下:
<tx:method name="涉及方法" read-only="false"/>
或者
<property name="transactionAttributes">
<props>
<prop key="涉及方法">PROPAGATION_SUPPORTS</prop>
</props>
</property>
<props>
<prop key="涉及方法">PROPAGATION_SUPPORTS</prop>
</props>
</property>