-->
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.  [ 3 posts ] 
Author Message
 Post subject: transaction sharing
PostPosted: Wed May 24, 2006 6:06 pm 
Newbie

Joined: Fri Dec 09, 2005 2:22 pm
Posts: 16
Hi,

how can I use the same transaction for some nhibernate updates and a native sql update ?
The ITransaction I get from the session hides the ADO transaction. So I have no means to access the underlying ADO transaction.

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 6:26 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
ITransaction exposes an Enlist method to which you can pass your IDbCommand object.

In other words:
Code:
ITransaction tx = session.BeginTransaction();

try
{
  AnObject obj = (AnObject)session.Get(typeof(AnObject), 1)
  obj.SomeProperty = "new value";

  SqlCommand sqlCmd = new SqlCommand();
  sqlCmd.Connection = session.Connection;
  sqlCmd.CommandText = "UPDATE MyTable SET MyField = "MyNewValue";

  tx.Enlist(sqlCmd);  //This is it...

  sqlCmd.ExecuteNonQuery();

  tx.Commit()
}
catch(Exception)
{
  tx.Rollback;
  throw;
}


Hope that helps.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 9:18 am 
Newbie

Joined: Fri Dec 09, 2005 2:22 pm
Posts: 16
great !
Exactly what I needed.

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.