Spring提供的Hibernate申明式事務(wù)管理有兩種辦法
Spring提供的Hibernate申明式事務(wù)管理有兩種辦法
a) 配合使用org.springframework.transaction.interceptor.TransactionInterceptor和org.springframework.orm.hibernate.HibernateTransactionManager,下面是spring reference的例子
代碼:












































HibernateInterceptor和事務(wù)無(wú)關(guān),它的用途在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中的例子
代碼:
































在沒(méi)有其他AOP interceptor情況下,使用TransactionProxyFactoryBean是比較方便的。
事務(wù)劃分一般是的業(yè)務(wù)層,而不是在DAO一層。
2.代理工廠返回的是接口AddressDao的應(yīng)用,通過(guò)接口最終調(diào)用target的方法。
3.TransactionDefinition定義了所有的事務(wù)屬性
posted on 2007-08-15 14:22 當(dāng)扎瓦 閱讀(519) 評(píng)論(0) 編輯 收藏 所屬分類: Spring