隨筆 - 3  文章 - 1  trackbacks - 0
          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          搜索

          •  

          最新評論

          • 1.?re: 不好的項目演示
          • 雖然項目演示失務,但我相信你的項目是最成功的,因為你的態度,你的聰明.

            You are NO.1! my lover
          • --roy117

          閱讀排行榜

          評論排行榜

          Spring提供的Hibernate申明式事務管理有兩種辦法

          a) 配合使用org.springframework.transaction.interceptor.TransactionInterceptor和org.springframework.orm.hibernate.HibernateTransactionManager,下面是spring reference的例子

          代碼:
          <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中的例子
          代碼:

              <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>
             


          在沒有其他AOP interceptor情況下,使用TransactionProxyFactoryBean是比較方便的。
          事務劃分一般是的業務層,而不是在DAO一層。

          2.代理工廠返回的是接口AddressDao的應用,通過接口最終調用target的方法。
          3.TransactionDefinition定義了所有的事務屬性



          Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=396860

          posted on 2008-04-01 17:49 terryliu 閱讀(232) 評論(0)  編輯  收藏 所屬分類: springhibernate
          主站蜘蛛池模板: 开原市| 甘孜| 桑植县| 平罗县| 海宁市| 衡阳县| 宁波市| 达孜县| 华亭县| 台前县| 德钦县| 玉树县| 渭源县| 温宿县| 息烽县| 紫金县| 上林县| 民县| 吉林省| 承德市| 石景山区| 收藏| 南川市| 双辽市| 宝兴县| 嫩江县| 新竹市| 清丰县| 时尚| 九台市| 丹阳市| 屯昌县| 紫阳县| 手机| 姜堰市| 怀宁县| 枣阳市| 汉中市| 姚安县| 丽江市| 乐业县|