IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope: Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Web development | Java technology  >

Spring 系列,第 2 部分: 当 Hibernate 遇上 Spring

Hibernate 事务天生适合 Spring AOP

developerWorks

返回文章

在打印这一页时,请选择 landscape 布局选项。


清单 2. 将应用程序 DAO 和 TransactionManager 编写在一起
<!-- Pass the session factory to our CustomerDAO -->
 <bean id="customerDAOTarget" 
     class="springexample.hibernate.CustomerDAOImpl">
   <property name="sessionFactory"><ref local="exampleSessionFactory"/>
   </property>
 </bean>
  <bean id="transactionManager" 
   class="org.springframework.orm.hibernate.HibernateTransactionManager">
   <property name="sessionFactory">
     <ref bean="exampleSessionFactory"/>
   </property>
  </bean>
  <bean id="userDAO"
   class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
   <property name="transactionManager"><ref local="transactionManager"/>
   </property>
   <property name="target"><ref local="customerDAOTarget"/>
   </property>
   <property name="transactionAttributes">
     <props>
       <prop key="addCustomer">PROPAGATION_REQUIRED</prop>
     </props>
  </property>
 </bean>

返回文章

    关于 IBM 隐私条约 联系 IBM 使用条款