Spring鎻愪緵鐨凥ibernate鐢蟲槑寮忎簨鍔$鐞嗘湁涓ょ鍔炴硶
a) 閰嶅悎浣跨敤org.springframework.transaction.interceptor.TransactionInterceptor鍜宱rg.springframework.orm.hibernate.HibernateTransactionManager錛屼笅闈㈡槸spring reference鐨勪緥瀛?/font>
浠g爜:
<beans>

<bean id="myTransactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="mySessionFactory"/>
</property>
</bean>
<bean id="myTransactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="myTransactionManager"/>
</property>
<property name="transactionAttributeSource">
<value>
product.ProductService.increasePrice*=PROPAGATION_REQUIRED
product.ProductService.someOtherBusinessMethod=PROPAGATION_MANDATORY
</value>
</property>
</bean>
<bean id="myProductServiceTarget" class="product.ProductServiceImpl">
<property name="productDao">
<ref bean="myProductDao"/>
</property>
</bean>
<bean id="myProductService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>product.ProductService</value>
</property>
<property name="target">
<ref local="myProductServiceTarget<"/>
</property>
<property name="interceptorNames">
<list>
<value>myTransactionInterceptor</value>
</list>
</property>
</bean>
</beans>




HibernateInterceptor鍜屼簨鍔℃棤鍏籌紝瀹冪殑鐢ㄩ斿湪javadocs涓弿榪板涓嬶細
寮曠敤:
This interceptor binds a new Hibernate Session to the thread before a method
call, closing and removing it afterwards in case of any method outcome.
If there already was a pre-bound Session (e.g. from HibernateTransactionManager,
or from a surrounding Hibernate-intercepted method), the interceptor simply
takes part in it.
b)浣跨敤TransactionProxyFactoryBean錛屼笅闈㈡槸Spring Reference涓殑渚嬪瓙
浠g爜:
<beans>

<bean id="myTransactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="mySessionFactory"/>
</property>
</bean>
<bean id="myProductServiceTarget" class="product.ProductServiceImpl">
<property name="productDao">
<ref bean="myProductDao"/>
</property>
</bean>
<bean id="myProductService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="myTransactionManager"/>
</property>
<property name="target">
<ref bean="myProductServiceTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="increasePrice*">PROPAGATION_REQUIRED</prop>
<prop key="someOtherBusinessMethod">PROPAGATION_MANDATORY</prop>
</props>
</property>
</bean>
</beans>

鍦ㄦ病鏈夊叾浠朅OP interceptor鎯呭喌涓嬶紝浣跨敤TransactionProxyFactoryBean鏄瘮杈冩柟渚跨殑銆?br>浜嬪姟鍒掑垎涓鑸槸鐨勪笟鍔″眰錛岃屼笉鏄湪DAO涓灞傘?/p>
2.浠g悊宸ュ巶榪斿洖鐨勬槸鎺ュ彛AddressDao鐨勫簲鐢紝閫氳繃鎺ュ彛鏈緇堣皟鐢╰arget鐨勬柟娉曘?br>3.TransactionDefinition瀹氫箟浜嗘墍鏈夌殑浜嬪姟灞炴?/p>

]]>