1 Reply Latest reply on Apr 2, 2008 12:10 PM by Pete Muir

    How to gracefully handle PersistenceException in EntityHome update method

    Mike McMahon Newbie

      I have a scenario where persisting some entity object fails in EntityHome.update due to a Hibernate Validator check. This is in a Seam EJB project and the EntityHome object is directly used by a seam-gen generated edit page, with the update being invoked via the save button click.

      In fact the validator here is used to simulate some unique constraint being violated upon commit.

      I am using a modified EntityHome.update that traps the Hibernate Validator exception, adds a FacesMessage about the problem and returns null instead of updated. The exception is indeed trapped; my problem is that I still receive an unhandled PersistenceException indirectly caused by the validator exception due to the transaction rollback.

      My question is, how can I handle this PersistenceException in a graceful manner? It seems not to be trappable inside the component (understandable, as it is likely thrown by the Seam interceptor wrapping my component). I would like to retain the user-entered state of the non-persisted object, display it again to the user and give them a chance to correct the problem and re-submit. How would I achieve this? Is it mandatory to involve pages.xml or can I manage to trap the exception within the component otherwise? Thank you.