Надлежащий способ настроить транзакции в Кидается за различными источниками данных?

Добавьте следующую строку до конца запроса SQL...

SELECT SCOPE_IDENTITY()

И затем используют метод ExecuteScalar на объекте SqlCommand...

var rowCount = command.ExecuteScalar()
10
задан matt b 24 September 2009 в 16:57
поделиться

2 ответа

Yes, you need a duplicate transaction advice. Notice in the following configuration that the pointcut expression selects a specific CompanyService bean.

<bean id="companyService1" class="com.company.service.CompanyServiceImpl">
  <property name="companyDao">
    <bean class="com.company.service.CompanyDAO">
      <property name="dataSource" ref="dataSource1"/>
    </bean>
  </property>
</bean>

<aop:config>
  <aop:pointcut
      id="companyServicePoint1"
      expression="bean(companyService1)"/>
  <aop:advisor
      advice-ref="companyServiceTxAdvice1"
      pointcut-ref="companyServicePoint1"/>
</aop:config>

<tx:advice id="companyServiceTxAdvice1" transaction-manager="txManager1">
  <tx:attributes>
    <!-- set propogation required on create methods, all others are read-only -->
    <tx:method name="create*" propagation="REQUIRED"/>
    <tx:method name="*" read-only="true"/>
  </tx:attributes>
</tx:advice>

<bean
    id="txManager1" 
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource1"/>
</bean>

To configure another CompanyService bean, you need to duplicate the same verbose boilerplate. Another way to demarcate transactions in Spring uses TransactionProxyFactoryBean. It's slighty less verbose because it uses a parent bean definition to configure common properties inherited by child beans.

<bean
    id="baseTransactionProxy"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
    abstract="true">
  <property name="transactionAttributes">
    <props>
      <prop key="create*">PROPAGATION_REQUIRED</prop>
      <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
  </property>
</bean>

<bean id="companyService1" parent="baseTransactionProxy">
  <property name="transactionManager" ref="txManager1"/>
  <property name="target">
    <bean class="com.company.service.CompanyServiceImpl">
      <property name="companyDao">
        <bean class="com.company.service.CompanyDAO">
          <property name="dataSource" ref="dataSource1"/>
        </bean>
      </property>
    </bean>
  </property>
</bean>

<bean
    id="txManager1" 
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource1"/>
</bean>
3
ответ дан 4 December 2019 в 04:21
поделиться

Вы пробовали использовать JtaTransactionManager?

http://forum.springsource.org/showthread.php?t=10476

0
ответ дан 4 December 2019 в 04:21
поделиться
Другие вопросы по тегам:

Похожие вопросы: