-->
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: Making NHibernate use existing IDbTransaction.
PostPosted: Thu Jan 26, 2006 5:05 pm 
Newbie

Joined: Thu Jan 26, 2006 4:22 pm
Posts: 6
Hi all,

We need to make NH create sessions using an existing IDbConnection and IDbTransaction. The IDbTransaction is being created in "legacy" (non NH empowered code) code and needs to call upon NH empowered code. Sometimes the NH empowered code may call Commit/Rollback sometimes the legacy code will.

Looking at the source code for NH we found that there is indeed a ITransactionFactory that resides on the Settings object.
The SettingsFactory.BuildSettings method builds this session object and in that method is the following code:

ITransactionFactory transactionFactory = new TransactionFactory();
// = TransactionFactoryFactory.BuildTransactionFactory(properties);
// TransactionManagerLookup transactionManagerLookup = //TransactionManagerLookupFactory.GetTransactionManagerLookup( properties );

Notice how it seems as if the original source was using an abstract factory (code commented out) but the port is linked to a specific factory implementation.

We can probably code our way around this by getting the settings object through reflection on the SessionFactImpl and once the SettingsObjects is obtained we should be able to replace the build-in implementation of ITransactionFactory on it with our own. We would also need to provide a custom implementation for ITransaction.

Before we go ahead an do this we would like to ask the community the following:

1) Has anybody solved the basic problem (getting NH to work with existing IDbTransactions) already and perhaps in a better way that this?

2) Does anybody know if this functionality is intended as part of the next version...and if confirmative are there any rough ideas on a release date?

3) Does anybody foresee problems with the approach outlined above to solve the problem? If we go ahead are we then likely to have to make huge changes when subsequent versions of NH are released based on current knowledge of the direction of the NH design?


Thanks in advance!

Christoffer Skjoldborg.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 5:04 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Hi,

you are the first to request a customizable ITransactionFactory actually. In Hibernate, I believe, it's used for distributed (JTA) transactions rather than plain database (JDBC) transactions.

In your case, I think the best solution would be to supply whole connections to NHibernate, not just transactions. Then, after NHibernate does its work, flush the ISession and commit your transaction.

You should just need to be careful and ensure that NHibernate sees changes you made in your legacy code. ISession.Evict and Refresh methods should help you in that.

Sergey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 7:55 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
I can't comment on your exact questions, but do please check out the castle project. They have implemented a transaction manager and have a specific nhibernate solution. (nhibernate facility)

http://www.castleproject.org/index.php/Main_Page

At the very least this should help you implement something of your own.

I hope this helps.


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.