-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Multiple databases in a single SQL server
PostPosted: Wed Jul 18, 2007 7:31 pm 
Newbie

Joined: Sat Jan 06, 2007 9:55 pm
Posts: 3
Requirement: We have a functionaltiy which needs to update both databases in a single transaction ( ie) make it atomic

Here is our current environment: there are two databases -->
Database1 and Database2( mapping shown below). They both reside on the same SQL server. Initially my thoughts were that we use two phase commit since I have created two session factory, also in which case I would need to use XA datasource and use JNDI.

But after talking to my SQL people, they advised me that since the two databases reside on the same SQL server, we dont need to use two phase commit but use one database connection and when updating both the databases specify the Database name.Table name then the database would understand which database and table to update and in this way we can update both the database and make it in a single transaction. I feel this is possible by using a pure JDBC connection, but we would like to use Hibernate and we dont want to bypass it.

So the question arises, is there a way to do this by hibernate? and do I need to use two phase commit?

here is my current mapping:

<bean id="dataSource1" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDrive r</value>
</property>
<property name="url">
<value>database1</value>
</property>
<property name="username"><value>abc</value></property>
<property name="password"><value>def</value></property>
</bean>
<bean id="sessionFactory1" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="dataSource"><ref local="dataSource1"/></property>

<property name="mappingResources">
<list>
<value>abc.hbm.xml</value>
</list>
</property>


</bean>
<bean id="transactionManager1" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory"><ref bean="sessionFactory1"/></property>
</bean>

<bean id="dataSource2" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
<property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDrive r</value>
</property>
<property name="url">
<value>database2</value>
</property>

<property name="username"><value>xxx</value></property>
<property name="password"><value>yyy</value></property>
</bean>




<bean id="sessionFactory2" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="dataSource"><ref local="dataSource2"/></property>

</property>

<property name="mappingResources">
<list>
<value>bbb.hbm.xml</value>

</list>
</property>

</bean>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.