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.  [ 5 posts ] 
Author Message
 Post subject: Mixing nHibernate Transaction with ADO.NET
PostPosted: Mon Jul 16, 2007 1:32 am 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
Hello,

I'm trying to mix nHibernate & Ado.Net transaction, is it possible? Here is the psudo code:

trx = mySession.BeginTransaction();
//do some hibernate stuff with mySession
IDBCommand cmd = mySession.Connection.CreateCommand();
cmd.CommandText = rawSql;
cmd.ExecuteNonQuery();
//some other stuff
trx.Commit();

I'm getting an exception from ADO when I do ExecuteNonQuery telling me that the command requires a transaction.

How can I assign the existing transaction (trx) to the Command (cmd).

I guess I could do cmd.Transaction = mySession.Connection.BeginTransaction();

But that's a new transaction.

Is there a way I can get around this?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 3:35 am 
Beginner
Beginner

Joined: Tue Jul 10, 2007 5:27 am
Posts: 34
Location: Belgium
try this:

trx.Enlist(cmd);

_________________
Davy Brion
http://ralinx.wordpress.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 11:35 am 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
Thank you! That worked!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 3:52 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
We do this quite a bit since we have a lot of legacy SQL access (and some long-time developers with political authority unfortunately resist using NHibernate and keep creating new code that does straight SQL). It seems to work OK for us ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 1:00 pm 
Beginner
Beginner

Joined: Fri Jan 12, 2007 1:08 am
Posts: 41
Another option is to use the ISQL interface as an alternative to straight ADO.NET


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