2 Replies Latest reply on May 7, 2010 10:55 PM by sai burgula

    how to catch NonUniqueObjectException and throw a message back to user

    sai burgula Novice

      I am getting a NonUniqueObjectException while I am trying to insert a row into a table.  As far as what is happening, it is happening correct.  But I would like to catch that exception and display a message back to the user.

      I will paste a sample code, so that it gives a better idea of what I am trying to accomplish.

      public String addPhdEdPlan() throws HibernateException{

          if(this.getAcademicYear() != null && this.getAcademicYear().length()>0){
                   Short academicYear = Short.valueOf(this.getAcademicYear());
      }catch(NonUniqueObjectException ne){
      throw new NonUniqueObjectException("Duplicate academic Year being added for this Student's Education Plan", PhdDataEdPlanId.class, PhdDataEdPlanId.class.getCanonicalName());

      /*facesMessages.add("Duplicate academic Year being added for this Student's Education Plan");*/


      So when I try and add a duplicate record, it should display this message on the screen, when the exception occurs.

      I hope I have conveyed my intention properly.

      Please let me know if it needs clarification.

      Hoping to hear soon.