views:

32

answers:

2

Hi all

If for example, I call session.Save(myObject), how do I determine if the operation succeeded or if it failed because my database server has been dropped out of a hang glider?

Does NHibernate throw a particular type of exception in this circumstance?

Thanks

David

+1  A: 

NHibernate will bubble up any exceptions that occur. These get wrapped in an NHibernate exception so you have to examine the InnerException(s) to get the original. In most cases, database operations are deferred until the session is flushed so you won't get error notifications immediately upon calling Save.

Since the load carrying capacity of a hang glider is very limited, I expect this specific issue will only occur with virtualized servers.

Jamie Ide
lolThanks for your aside!Good point on the Flush - so I need to call it specifically if I want to catch the Exceptions. I assume Transaction.Commit flushes the session?
David
You always need to call Flush or commit the transaction to persist changes to the database.
Jamie Ide
That sounds like a yes. Thanks!
David
A: 

Not sure about NHibernate, but Hibernate depends on other code like, c3p0 for connection pooling and other connection related services. So if connection is lost, then this connection pooler should throw some exception, which probably gets wrapped, as Jamie suggested.

Abhijeet Kashnia