View Full Version : Spring + enterprise services + nhibernate integration
maxintech
06-13-2007, 07:44 PM
Hi, sorry for my english, exists some fragment or example using nhibernate in a component inside com+ and using com+ transaction demarcation.
I created components, using de Calculator example. I used nhibernate in other project, called directly from middle tier. I need one dao, one hbm and some configuration on com+ side.
Thank you in advance.
maxintech
06-13-2007, 09:00 PM
I use Spring.net 1.1.0 Preview 3.
I can change to 1.1 M1 if need it
Mark Pollack
06-13-2007, 09:03 PM
Hi,
What database are you using and what version of NHibernate?
Mark
Mark Pollack
06-14-2007, 02:30 AM
Based on this post (http://forum.hibernate.org/viewtopic.php?t=955211), which is a bit old BTW, if you are using standard COM+ to manage the transactions then when the session creates the connection it will automatically be enlisted in the existing distributed transaction (assuming you start the transaction before opening the session). Some database providers don't do that so you should check. However, NHibernate needs to be notified when the transaction ends so that it can do housekeeping on its second level cache, otherwise the second level cache could be in an inconsistent state. To do this one would have to develop a COM+ compensating resource manager to be notified, not a trivial task, and it isn't provided in NH 1.2. So you could either, 1) not use the 2nd level cache, 2) figure out another way to call ISessionImplementor.AfterTransactionCompletion() when the transaction completes, or 3) use one of Spring.NET's transaction managers to control the transactions along with Spring's HibernateTemplate.
If you choose #3, and need distributed transactions in .NET 1.1, then you can use ServiceDomainPlatformTransactionManager. When you use Spring's HibernateTemplate it will register with the platform transaction manager a 'SpringSessionSyncrhonization' object that will be notified on completion or rollback of the transaction and will then call the appropriate NHibernate methods.
However, if you were using COM+ just to get declarative transaction management and you don't really need distributed transactions, then use Spring's HibernateTransactionManager and declarative transaction management features.
Depending on what route you take, let me know if I can help some more.
Regards,
Mark
maxintech
07-04-2007, 04:27 PM
Thank you for your answer.
I use net2.0 and don't need distributed transaction. There will be only one server for the application over w2003 server. The database is a SQL Server 2005 Enterprise
The use of COM+ is a client requirement for demarcation of the transaction. I will prefer other solution for a simple deploy schema. :(
I prefer the option #3. Can I choose TxScopeTransactionManager instead of ServiceDomainPlatformTransactionManager for a simple non distributed transaction?
Thank you again.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.