1 Reply Latest reply on Sep 10, 2005 7:02 AM by sisepago

    ObjectNotFoundException - But I know it might not be there

    mcaughey

      I've got a problem that I expect is not unusual. I may simply be approaching this the worng way. I'm doing a look up in a table where the primary key may not exists. I'm using session.load( class, Integer ) to find my object.

      Person person = (Person)session.load( Person.class, new Integer(personId) );
      


      person == null is always false.

      So I do the following:
      try{
       if(person.getPersonId() > 0);
      }catch(ObjectNotFoundException e){
       // do nothing
      }
      
      // code continues
      
      


      If the person object was not loaded the when I do the getPersonId() the ObjectNotFoundException is thrown. Well what I found out was there is a callback event listener handling the exceptions thrown in the concrete class of my Person Object. I cannot catch the exception it is being thrown to and handled by a class called DefaultLoadEventListener.

      My code works fine, but my log files are filling up with stack traces everytime one of these are thrown, and I don't care that they are being thrown. They are logged as Errors in log4J so I cannot even adjust the log level with out potentianly missing other important logging info coming from that class.

      Is there a better way?

      Is there something I can do to turn off thoose nasty stacktraces for this senerio?

      Thanks,
      Michael