1
 <bean id="projectService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager" ref="transactionManager"/>
    <property name="target">
        <bean class="com.company.project.company.services.ServiceImpl" init-method="init">

             <property name="HRappsdao" ref="HRappsdao"/>
               <property name="projectdao" ref="projectdao"/>

        </bean>
    </property>
    <property name="transactionAttributes">
        <props>
            <prop key="store*">PROPAGATION_REQUIRED</prop>
            <prop key="update*">PROPAGATION_REQUIRED</prop>
            <prop key="remove*">PROPAGATION_REQUIRED</prop>
            <prop key="bulkUpdate*">PROPAGATION_REQUIRED</prop>
            <prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
        </props>
    </property>
</bean>

2つのデータソースHRappsdaoとprojectdaoがあり、どちらも異なるsessionFactoryを使用しています。この場合、私のtransactionmanagerはどのsessionfactoryを使用する必要がありますか?(hrappsdaoまたはprojectdao)?

編集

<bean id="transactionManager" 

class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" >  //my HRappsdao using same 
            <ref local="sessionFactory"/>
        </property>
    </bean>
4

1 に答える 1

3

実際には、トランザクションマネージャーの構成が表示されていないため、現在何を使用しているかはよくわかりませんが、ドキュメントを引用しています。

JTA(通常はを通じてJtaTransactionManager)は、同じトランザクション内の複数のトランザクションリソースにアクセスするために必要です。

Spring 2.5では、基盤となるJTAベースのトランザクションプラットフォーム(ほとんどのアプリサーバーで動作)を自動検出するための「新しい」構成要素の使用を検討してください。9.8<tx:jta-transaction-manager/>章を参照してください。詳細については、アプリケーションサーバー固有の統合を参照してください。

古いバージョンのSpringを使用している場合は、JtaTransactionManager手動で構成する必要があります。JTA TransactionManagerのJNDIの場所は各J2EEサーバーに固有であるため、これにはアプリケーションサーバーに関するある程度の知識が必要です。

詳細を入力してください(詳細なガイダンスが必要な場合は、Springのバージョンや使用しているアプリケーションサーバーなど)。


更新:私が言ったように、複数のデータソースを使用する場合はJtaTransactionManager、ではなくを使用する必要がありますHibernateTransactionManager(javadocを参照)。Spring 2.5を使用している場合は、Spring構成を次のように更新します。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"       
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <tx:jta-transaction-manager />

    <!-- 
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            //my HRappsdao using same
            <ref local="sessionFactory" />
        </property>
    </bean>
    -->

    ...

</beans>

TomcatまたはJettyを備えたJOTMのようなものが必要になることに注意してください。JBossやGlassfishな​​どのJ2EEアプリサーバーへの移行を検討する必要があります。

于 2009-12-26T03:59:26.510 に答える