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

    how to catch NonUniqueObjectException and throw a message back to user

      Hi

      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{

      try{
                                                                     
          if(this.getAcademicYear() != null && this.getAcademicYear().length()>0){
              if(!isDuplicate()){
                   Short academicYear = Short.valueOf(this.getAcademicYear());
                   phdDataEdPlan.getId().setAcademicYear(academicYear);
              }
          }
      }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.

      thanks
      Sai