1. 程式人生 > >spring-hibernate修改資料報錯

spring-hibernate修改資料報錯

1.org.springframework.dao.InvalidDataAccessApiUsageException: 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.

執行的方法不再設定範圍內,hibernate預設為readonly:解決方案,將方法對應的包移動至com.document包下

<aop:config>
<aop:pointcut id="bussinessService"
expression="execution(public * com.document..*.*(..))" />
<aop:advisor pointcut-ref="bussinessService"
advice-ref="txAdvice" />
</aop:config>


<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- <tx:method name="getUser" read-only="true" /> -->
<!-- <tx:method name="add*" propagation="REQUIRED"/> -->
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>