Posted on 2010-08-18 15:56
瘋狂 閱讀(1481)
評論(0) 編輯 收藏 所屬分類:
java 、
database 、
questions 、
spring 、
hibernate 、
web
使用順序:
1 <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
之后才是xml配置:
2 <tx:advice id="txAdviceService" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" read-only="false"/>
<tx:method name="add*" read-only="false"/>
<tx:method name="update*" read-only="false"/>
<tx:method name="del*" read-only="false"/>
<tx:method name="apply*" read-only="false"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="serviceMethods"
expression="execution(* com.joe.service.*.*(..))"/>
<aop:advisor advice-ref="txAdviceService" pointcut-ref="serviceMethods"/>
</aop:config>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
如果寫反會出現如果使用的
@Transactional的方法在 <tx:method name="*" read-only="true"/>
里面 就會發現沒有可寫事務 :
error: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.