NHibernate - how do you know if database operation succeeded?
If for 开发者_JAVA技巧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
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.
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.
精彩评论