xml配置
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 事务通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="add*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="edit*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="remove*" propagation="REQUIRED" isolation="DEFAULT"/>
<tx:method name="*Tran" propagation="REQUIRED" isolation="DEFAULT" />
<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT"/>
</tx:attributes>
</tx:advice>
exception 提示
1.
Cause: java.sql.SQLException: Connection is read-only.
Queries leading to data modification are not allowed
2.
cannot execute CREATE DATABASE in a read-only transaction
以上均是由springxml中check* <prop key="*">readOnly</prop> 配置引起的,
方法的事务设置只读,说明调用这个方法时事务只能查询,不能增删改,这样就提高了性能,如果增删改,就会报错;
具体关于事物readOnly控制,可查看文章: http://boy00fly.iteye.com/blog/1142754