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>

i have 2 datasource HRappsdao and projectdao, both are using different sessionFactory. in this case, my transactionmanager should be using which sessionfactory? (hrappsdao or projectdao) ?

editted

<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 中,考虑使用“ new<tx:jta-transaction-manager/>配置元素来自动检测基于 JTA 的底层事务平台(适用于大多数应用服务器)。见第9.8 章。应用程序服务器特定的集成以获取更多详细信息。

如果您使用的是旧版本的 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 回答