views:

221

answers:

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>
+1  A: 

Actually, you're not showing the configuration of your transaction manager so I'm not really sure of what your are currently using but, quoting the documentation:

JTA (usually through JtaTransactionManager) is necessary for accessing multiple transactional resources within the same transaction.

With Spring 2.5, consider using the "new" <tx:jta-transaction-manager/> configuration element for automatic detection of the underlying JTA-based transaction platform (works with most app servers). See the chapter 9.8. Application server-specific integration for more details on this.

If you are using an older version of Spring, you'll need to configure your JtaTransactionManager manually. This will require some knowledge of your application server as the JNDI location of the JTA TransactionManager is specific to each J2EE server.

Please provide more details (like the version of Spring and the application server you are using if you need more guidance).


UPDATE: As I said, when using multiple datasources, you need to use the JtaTransactionManager and not the HibernateTransactionManager (see the javadoc). If you are using Spring 2.5, update your Spring configuration as below:

<?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"&gt;

    <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>

Note that you'll need something like JOTM with Tomcat or Jetty. You should maybe consider moving to a J2EE app server like JBoss or Glassfish.

Pascal Thivent
above is how my transactionmanager using sessionFActory. but i have 2 sessionfactory because of 2 different datasource. so i wonder in this case, how to use transactional
cometta
also my application server is just tomcat/jetty. not using j2ee container
cometta