1 Reply Latest reply on Jun 9, 2010 2:35 PM by Serkan Eskici

    How to handle validator and exception gracefully in ManyToOne relation?

    Sean Wu Newbie

      Hi all,


      A big advantage of seam is to handle validator and exception. For example, you can check a Person's email is not null or empty or valid and get an error message when submit it or just lose the focus (ajax). It can be handled easily if this is a field with simple type like String. My scenario is I have three entities: person, employment and company. Employment contains a person, a company and a period.
      So person and employment is a OneToMany relation, the same is true for company and employment. Of course, employment must contain person and company with notnull annotation. When I test to persist a employment without a person or a company, Seam will direct me to a debug page with javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value exception which is not graceful like email validation. I hope I can get a error message like 'Employment must contain a person and a company in the same page of submit button. How do I achieve this? I've read seam exception document and think catch org.hibernate.PropertyValueException or PersistenceException is not what I want. Thanks a lot.

        • 1. Re: How to handle validator and exception gracefully in ManyToOne relation?
          Serkan Eskici Novice

          There are many ways to do this:



          1. page specific solution: put your code between try-catch, catch the exception and create a FacesMessage. Or bind your JSF componont to a validator e.g. a method in your bean and validate it there before doing a CRUD.

          2. general solution: configure the exception in your pages.xml and set a general message inside it (you must disable debug mode in Seam & Facelets to see this working). Or you can write an @Observer(with the name of the exception) and create a FacesMessage(s) inside it.



          Hope this helps.