-->
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.  [ 2 posts ] 
Author Message
 Post subject: Is this possible? One SQL + two databases + one transaction
PostPosted: Thu Jan 22, 2009 6:08 am 
Newbie

Joined: Sun Jun 22, 2008 9:22 pm
Posts: 4
Hi,

I know how to use two different session factories to deal with two different databases. But if the two databases are in the SAME SQL server instance, is it possible to group them under the same transaction?

Thanks,
- Patrick


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2009 2:52 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
ITransactions are instantiated through ISession so I don't think this is available using default NH functionality. As an example:

Code:
ISessionFactory sessionFactory = configuration.BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
ITransaction tran = session.BeginTransaction();

As you can see, the transaction is associated with a session which is associated with a database. I don't see how you'd be able to have that transaction span two distinct session objects (with connections to your distinct databases on the same instance).

Even if you had two session factories and therefore two sessions, I don't think you could get away with it. If a Commit() fails on a transaction, you are supposed to abandon the session. What happens if your first commit() on session1 works but the commit on session2 fails? Imagine:
Code:
ISession session1 = sessionFactory1.OpenSession();
ISession session2 = sessionFactory2.OpenSession();

ITransaction tran1 = session1.BeginTransaction();
ITransaction tran2 = session2.BeginTransaction();

session1.DoSomeWork();
session2.DoSomeMoreWork();

try {
   tran1.Commit();
   tran2.Commit();
} catch (Exception ex) {
   throw ex;
}

I don't see how you'd be able to back out of the first transaction if the second one failed. If you can figure that out, then you might have a chance.

-devon


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

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.