트 랜 잭 션 전파 행위 종류

4826 단어 사무.
Spring TransactionDefinition      7          ,                             :

 1        

        
   
 
PROPAGATION_REQUIRED
         ,       ,           ,        。        。
 
PROPAGATION_SUPPORTS
       ,        ,         。
 
PROPAGATION_MANDATORY
        ,        ,     。
 
PROPAGATION_REQUIRES_NEW
     ,        ,       。
 
PROPAGATION_NOT_SUPPORTED
           ,        ,        。
 
PROPAGATION_NEVER
         ,        ,     。
 
PROPAGATION_NESTED
         ,         。        ,    PROPAGATION_REQUIRED     。
 

   PROPAGATION_NESTED ,          JDBC 3.0,                。


<!--Hibernate     -->
<bean id="transactionManager"
   class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory">
    <ref bean="sessionFactory" />
   </property>
</bean>

<!--        bean-->
<bean id="transactionInterceptor"
   class="org.springframework.transaction.interceptor.TransactionInterceptor">
   <!--      bean             -->
   <property name="transactionManager" ref="transactionManager" />
   <property name="transactionAttributes">
    <!--           -->
    <props>
     <prop key="save*">PROPAGATION_REQUIRED</prop>
     <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
     <prop key="delete*">PROPAGATION_REQUIRED</prop>
     <prop key="update*">PROPAGATION_REQUIRED</prop>
     <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
   </property>
</bean>

<bean id="managerTemplate" abstract="true" lazy-init="true">
<property name="teamDao">
   <ref bean="teamDao" />
</property>
<property name="studentDao">
   <ref bean="studentDao" />
</property>     
</bean>

<bean id ="manager" class="com.zd.service.impl.Manager" parent="managerTemplate" />

<!--   BeanNameAutoProxyCreator-->
    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
     <!--        bean name bean         -->
     <property name="beanNames">
            <!--                 bean-->
            <list>
                <value>manager</value>
            </list>
            <!--                   bean-->
     </property>
        <!--     BeanNameAutoProxyCreator        -->
        <property name="interceptorNames">
            <list>
                <!--          Interceptor -->
                <value>transactionInterceptor</value> 
            </list>
        </property>
    </bean>

<!--         -->
<bean id="baseDao" class="com.zd.service.impl.BaseDao">
    <property name="hibernateTemplate">
      <ref bean="hibernateTemplate"/>
    </property>
</bean>

<!--    -->
<bean id="teamDao" class="com.zd.service.impl.TeamDao">
    <property name="baseDao">
       <ref bean="baseDao" />
    </property>
</bean>

<!--    -->
<bean id="studentDao" class="com.zd.service.impl.StudentDao">
    <property name="baseDao">
       <ref bean="baseDao" />
    </property>
</bean>


public void testSaveTeam() {
   Team team = new Team();
   team.setTeamId(DBKeyCreator.getRandomKey(12));
   team.setTeamName("Class CCC");
   IManager manager = (IManager) SpringContextUtil.getContext().getBean("manager");
  

   Student student = new Student();
   student.setStudentId(DBKeyCreator.getRandomKey(13));
   student.setSex(Student.SEX_FEMALE);
   student.setStudentName("Tom");
   student.setTeamId("60FHDXDIG5JQ");
   manager.saveTeamAndStu(team, student);
   System.out.println("Save Team and Student Success");

 

좋은 웹페이지 즐겨찾기