Announcement Announcement Module
Collapse
No announcement yet.
transactions across multiple datasources Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • transactions across multiple datasources

    Hi,

    I have a DAO that extends HibernateDaoSupport and is proxied by a TransactionProxyFactoryBean. The relevant dataSource, sessionFactory, and transactionManager are all defined in a standard way.

    Code:
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    	<property name="driverClassName"><value>${jdbc.driverClassName}</value></property>
    	<property name="url"><value>${jdbc.url}</value></property>
    	<property name="username"><value>${jdbc.username}</value></property>
    	<property name="password"><value>${jdbc.password}</value></property>
    </bean>
    
    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    	<property name="dataSource"><ref local="dataSource"/></property>
    	<property name="mappingResources">
    		<list> <!-- .hbm.xml files listed here --> </list>
    	</property>
    </bean>
    
    <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
    	<property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
    However, in addition to accessing the datasource defined by the "dataSource" bean, the DAO calls methods which access another datasource. These reads/writes are obviously outside the control of the defined "transactionManager", but I would like to bring them under it's control. Is it possible to define a transactional proxy for a DAO that reads/writes multiple datasources?

    Thanks in advance,
    DM

  • #2
    You would have to use JTA. Spring by itself cannot support multiple db's.

    Comment


    • #3
      Thanks for the reply. Presumably to use Spring with JTA I need to change the implementation class of the transaction manager bean. Using JTA, how do I configure a Hibernate session factory that works with muliple datasources?

      Comment


      • #4
        You don't a SessionFactory works with one datasource only. So you would need to define multiple SessionFactories.

        Comment

        Working...
        X