-->
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.  [ 12 posts ] 
Author Message
 Post subject: joining SqlTransaction with NHibernate transaction
PostPosted: Sun Jun 26, 2005 9:24 pm 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Hi, can I join a SqlTransaction with an NHibernate transaction? Thanks in advance.


Top
 Profile  
 
 Post subject: anyone?
PostPosted: Wed Jun 29, 2005 11:22 pm 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Guys. Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 8:06 am 
Newbie

Joined: Thu May 26, 2005 2:37 am
Posts: 3
Location: Czech Republic
:evil: That's not posssible... it seems.
You have to start an ITransaction first and then use ITransaction.Enlist to enlist your SqlCommands.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 9:26 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
You can do it the other way too. You can start an ADO.NET transaction on an SqlConnection object and then create a new NHibernate session with your own SqlConnection (by passing it to the OpenSession method). This will enlist NHibernate in your transaction.

Joining two separate and distinct transactions requires the use of a distributed transaction controller (two-phase commit).


Top
 Profile  
 
 Post subject: What does "Joining SqlTransaction" means here?
PostPosted: Fri Jul 22, 2005 4:12 pm 
I have a similar problem but I don't wish to join a NHibernate transaction with a SqlTransaction. I need to use the wrapped Local SqlTransaction in the NHibernate transaction.

I have a class for printing a paper form. It takes a SqlTransaction for querying data for printing. Therefore, I have to use the SqlTransaction in ITransaction or the data is not visible in another connection.

What I though is someting like

public IDbTransaction GetLocalTransaction( ) in ITransaction.

Is this possible?
Thanks


Top
  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 9:15 pm 
Create the ADO connection and transaction yourself manually, then pass the connection object to OpenSession to base the NHibernate session on your manually created connection and transaction.

You will still have a reference to the transaction at this point for use in your report query.


Top
  
 
 Post subject: ... Thanks but I'm targetting two diff DB's
PostPosted: Tue Sep 20, 2005 4:56 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Thanks, but I dont think this would work as I'm targetting two different databases:

Code:
Dim trx As System.Data.IDbTransaction
Dim conn_Sales As System.Data.IDbConnection 'Connection to database 'Sales'
Dim factory_Warehouse As NHibernate.ISessionFactory
Dim sess_Warehouse As NHibernate.ISession 'Connection to warehouse database

conn_sales = new SqlConnection(connstr)
trx = conn_sales.BeginTransaction(IsolationLevel.Serializable)
...
'I can't open a session to 'Warehouse' database passing in a connection to 'Sales' database in order to share transaction.
sess_Warehouse = factory_Warehouse.OpenSession(conn_Sales)

trx.Commit()


Help anyone??


Top
 Profile  
 
 Post subject: Enlist?
PostPosted: Tue Sep 20, 2005 5:04 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Quote:
You have to start an ITransaction first and then use ITransaction.Enlist to enlist your SqlCommands.


Can anyone give code snippnet on how ITransaction.Enlist can be applied?

Anyway, I don't have a IDbCommand object handy because it's wrapped inside a DAO (Data Access Object). So... this is probably not...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 8:41 am 
Newbie

Joined: Thu May 12, 2005 10:40 am
Posts: 16
snip.. ;-)
Code:
    static internal int GetRowCount(ISession s,string sDbTable,string sDbColumn, bool bColumnIsString, string sObjId) {
      int nRet = 0;
      try {
        System.Data.IDbCommand updCmd = s.Connection.CreateCommand();
        updCmd.CommandText = "SELECT count(*) as sum_rows FROM " + sDbTable + " WHERE " + GetColumnEqualsCondition(sDbColumn,bColumnIsString,sObjId);
        updCmd.CommandType = System.Data.CommandType.Text;
        s.Transaction.Enlist(updCmd); 
        nRet = (int) updCmd.ExecuteScalar();
...


Top
 Profile  
 
 Post subject: ... so, back to the problem when you have two databases
PostPosted: Tue Sep 20, 2005 9:24 pm 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
... so, back to problem when you have two actions targetting two databases and your transaction need to span over these two actions... anyone has anything to share/offer in this regards?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 5:39 am 
Newbie

Joined: Thu May 12, 2005 10:40 am
Posts: 16
have a search for
DTP - Distributed Transaction Processing
Maybe there's a design pattern how to handle this ...
Obvisiously this requires some kind of transaktionsmanager,
which as far as i can see, is out of a nhibernate-focus


Top
 Profile  
 
 Post subject: ... thanks for the comment i been away...
PostPosted: Mon Oct 24, 2005 2:24 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Hey thanks for the feedback I have been away for awhile...


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