开发者

Castle ActiveRecord SessionScopeWebModule exception handling

I have a Web app with SessionScopeWebModule enabled, and I wonder how to best handle business exceptions (not Hibernate / DB exceptions).

I believe AR 2.0 SessionScopeWebModule implicitly implements transaction - if an exception occurs during the request, changes made during the session will be discarded / rolled back.

For my Web app, the business layer will be chatty with the DB, issuing several CRUDs, say

Say entity A has been created. However upon creating entity B some business rules were not observed and the business layer throws a business exception.

From the UI perspective, it's best to 'handle' the business exception and display a friendly message back to the user. This is where the problem lies. If the exception is already handled, SessionScopeWebModule goes along thinking everything is fine at the end of the request and commits the entity A into database, without entity B.

What is the best practice to handle exceptions in this case? I'm thinking of a session variable that will be reset for each new request. If an exception occurs, the variable will be marked dirty. When the request ends, the SessionScopeWebModule will first check the session to see if any exception has occured. If so, it will invoke a FailSession.

Is this the way to go? And would FailSession do the job of discarding changes to a session?

Thanks!

Boyan


on the website http://www.summerofnhibernate.com/ I have sean a web-chast about this topic (it's part 13), but with NHibernate directly (without ActiveRecord). I explains how and why the Session saves/flushes and how to stop it from doing that. Perhaps the informations from that video can help you.

Greetings Juy Juka

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜