Friday, June 13, 2008

Nhibernate with tirggers

I was working on Nhibernate Framework, I found a feature in this framework that I want to explain you.
I have to make a transaction between two tables they have parent and child relation on child creation or updating a trigger is fired take sum of child rows and update into parent.
Everything doing fine with transaction no exception but no updating in parent record after hitting trigger.That’s amazing for me .Long story short actually Nhibernate having a state of parent with previous values again updated on commit of transaction.So, I have to create a separate transaction for parent and child also. And don’t forget to Call NHibernateSession.Flush();after commit a transaction. Like
BaseDao.NHibernateSession.Transaction.Commit();
NHibernateSession.Flush();

But it’s very critical in the situation when you have to ensure that every thing should be in one go(transaciton) then realy it’s a question.I had faced this problem in the same project,but fourtunately I have a columns which shows record is deleted in first transaction I pass this true isdeleted=true and after commiting and flushing .Begin another transaction the then pass isdeleted=false.Because my trigger only works on isdeleted=false record.Anyhow its just a one solution which works in my scenario.if any one has some good idea please share with us.

No comments: