[jboss-user] [JBoss Seam] - Exception handling of PersistenceException

dapeng do-not-reply at jboss.com
Mon Nov 12 11:09:19 EST 2007


Hi,

Hibernate executes the statements only on flushing, which is most of the time at the end of a tx. It means, any database related exception (foreign key constraint or unique constraint etc.) will be thrown in a deferred fashion(not at the time of invocation, but at the time of tx commitment).  At the end of the 5 and 6 JSF phases, a TransactionRolledBackException is thrown, when all action methods have been executed. There is no chance to catch such kind of ConstraintException in service layer or in JSF actions. 

What is the best-practice for handling these exceptions? 

The normal behaviour I excpeted from the system is to add a faces message and stay on the same view. I think the only guy who can do this job is a  ExceptionHandler. First question is why not allow to add user defined ExceptionHandler? Second question is: Can I use any of the existing handler to implement the desired behaviour? In the documentation I only see examples which redirects to another view. Is there a shortcut (EL-expression) to find out the current view and use it as thre redirection target? If not, I would like to implement it. My plan is to use a PhaseListener to catch the current view and put it somewhere (request attribute or thread locale, anyway, anywhere reachable by a EL-expression) for later use and configure in the pages.xml

<exception class="javax.persistence.PersistenceException">
  | <end-conversation/>
  | <redirect view-id="{el-expression-to-the-current-view}">
  | <message>Database access failed</message>
  | </redirect>
  | </exception>
  | 
I would like to know your opinions to the solution. Whether you have better suggestion or see general problems

thx for your feedback!



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4103756#4103756

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4103756



More information about the jboss-user mailing list