没用过spring的jta,也想知道!

解决方案 »

  1.   

    根据spring的文档:global transaction是由app server管理,使用jta如果你在spring中使用申明式的事务,那么可以很方便的在jta和local transaction之间转换,不用改代码
      

  2.   

    asklxf(xuefeng): 
    你的意思还是单个数据源下的情况:只不过是用jtaTransactionManager 来控制事务罢了,那样 程序式事务 也是不用改变代码的。其实这还是 localTransactions
    但是我的意思是:如果用jtaTransactionManager,那就要是 globalTransactions 了。就是说是两个数据源 两个连接,执行的是两阶段提交:如:bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/><bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
      <property name="userTransaction"><ref local="jotm"/></property>
    </bean><bean id="globalDataSource1" class="org.enhydra.jdbc.standard.StandardXADataSource">
      <property name="driverName">...</property>
      <property name="url">url1</property>
    </bean><bean id="globalDataSource2" class="org.enhydra.jdbc.standard.StandardXADataSource">
      <property name="driverName">...</property>
      <property name="url">url2</property>
    </bean>比如我现在有两张表:vender 和 agreement 两个表:vender 在 globalDataSource1 里
    agreement 在 globalDataSource2 里<bean id="venderDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

    <property name="transactionManager">
    <ref bean="transactionManager" />
    </property> <property name="target">
    <ref local="venderDAO" />
    </property> <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property></bean><bean id="venderDAO" class="com.bjhuajia.silver.dao.ExtDao">
    <property name="dataSource">
    <ref local="globalDataSource1" />
    </property>

    <property name="transactionManager">
    <ref local="transactionManager" />
    </property>
    </bean>
    <bean id="agreemnentDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">

    <property name="transactionManager">
    <ref bean="transactionManager" />
    </property> <property name="target">
    <ref local="agreementDAO" />
    </property> <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property></bean><bean id="agreementDAO" class="com.bjhuajia.silver.dao.AgreementDao">
    <property name="dataSource">
    <ref local="globalDataSource2" />
    </property>

    <property name="transactionManager">
    <ref local="transactionManager" />
    </property>
    </bean><bean id="BusinessProxy"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref bean="transactionManager" />
    </property><property name="target">
    <ref local="business" />
    </property><property name="transactionAttributes">
    <props>
    <prop key="do*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>
    在 bussiness layer 控制事务public class business{
      

  3.   

    <bean id="business" class="com.bjhuajia.silver.Business">
    <property name="transactionManager">
    <ref local="transactionManager" />
    </property>
    </bean>在 bussiness layer 控制事务public class business{
    public void doWork(Info Info) {
        JdbcTemplate jt = new JdbcTemplate();
        jt.update("insert into Vender (venderName) values ('asdfa')");
        jt.update("insert into Agreement(agreementName) values ('asdfas");
    }}
    Business bs = (Business) factory.getBean("business");
    bs.doWork(info);晕了:大概是这样做吗。哪位知道:spring 的分布式事务 必须要梆钉 到 appserver 才有效吗。疑惑
    如果干用jotm 做 分布式事务的话,也不需要appserver 啊。 直接在tomcat 就可以了。
    我看 spring 也是用的 jotm 的吗。
      

  4.   

    根据spring的文档:(我只看了官方文档,没有深入研究)只要是分布式事务,即有多个数据源,必须用jta,而管理分布式事务必须需要一个app server(weblogic, jboss...),也就是说global transaction必须邦定到app server的jndi,spring自己并不能创建只是负责查询jndi得到jta
      

  5.   

    附:
    Furthermore, a JTA UserTransaction normally needs to be obtained from JNDI: meaning that we need to use both JNDI and JTA to use JTA. Obviously all use of global transactions limits the reusability of application code, as JTA is normally only available in an application server environment.(Spring Framework Version 1.1, page 70)
      

  6.   

    Spring's transaction management capabilities--and especially its declarative transaction management--significantly changes traditional thinking as to when a J2EE application requires an application
    server.In particular, you don't need an application server just to have declarative transactions via EJB. In fact, even if you have an application server with powerful JTA capabilities, you may well decide that Spring declarative
    transactions offer more power and a much more productive programming model than EJB CMT.You need an application server's JTA capability only if you need to enlist multiple transactional resources.Many applications don't face this requirement. For example, many high-end applications use a single, highly
    scalable, database such as Oracle 9i RAC.Of course you may need other application server capabilities such as JMS and JCA. However, if you need only JTA, you could also consider an open source JTA add-on such as JOTM. (Spring integrates with JOTM out of
    the box.) However, as of early 2004, high-end application servers provide more robust support for XA transactions.The most important point is that with Spring you can choose when to scale your application up to a full-blown application server. Gone are the days when the only alternative to using EJB CMT or JTA was to write coding using local transactions such as those on JDBC connections, and face a hefty rework if you ever needed that code to run within global, container-managed transactions. With Spring only configuration needs to change: your code doesn't.这是文档:if you need only JTA, you could also consider an open source JTA add-on such as JOTM. (Spring integrates with JOTM out of
    the box.) 这句话的具体是什么意思。
      

  7.   

    JTA一般都是app server提供的,如果不用app server只用jta(我觉得这种情况很少出现,所以spring说JTA is normally only available in an application server environment.),那就考虑实现了jta但不是app server的JOTM
      

  8.   

    如果用jotm 来做分布式的事务,是不需要的appserver 的。
    而 jotm 是兼容 jta 的。这又如何解释呢。
    spring 用的也是jotm 呀。
    很少出现不代表没有。