2 Replies Latest reply on Apr 4, 2005 5:03 PM by Juraj Holtak

    Exception Handling for Entity Beans

    Juraj Holtak Newbie

      How are you folks handling Exceptions from EntityManager operations?
      Maybe I`m blind but I can`t find anything reasonable in the EJB3 Draft.

      My first idea was to

      try{...do manager actions...}
      catch(Exception e){
      //log some stuff here
      throw new WrappedPersistenceException("Persistence messed again!",e);
      }
      

      in the DAO-Bean

      but this is childisch and good for my personal homepage

      I need to provide more finegrained exceptions and actually tell the user, what went wrong and WHY it went wrong. I also need to provide some "error codes" for the user support.

      I could do all that, but I need to know, what exceptions the manager can throw. As they are not mentioned in the draft :-( , where can i find them except the jboss cvs ;-). Are they jboss/hibernate specific?

      I also would like to use AOP for this task somehow. Anybody done something similar?




        • 1. Re: Exception Handling for Entity Beans
          Bill Burke Master

          In the EDR specification, look at the Javadoc decls in the EntityManager interface and Query interface. There's a lot of information on what exceptions *should* be thrown. This doesn't guarantee that JBoss EJB3 has implemented the behavior yet! If you find that we don't throw correct exceptions, then please log a bug on jira.jboss.com. For instenace, Preview 4 does not handle finds correctly and throws a specific Hibernate exception rather than an EJB3 one.

          Thanks for your input though, I will put in a Jira task to make sure how we document on how to use AOP to hook in your own exception handling.

          Regards

          • 2. Re: Exception Handling for Entity Beans
            Juraj Holtak Newbie

            thank you!

            yes, the first exception I tried was, when entity not found, from a find and seeing some hibernate exceptions flying around, I started worying and "loosing the checker-feeling". I see its corrected in preview5, which is scheduled soon, so I think I`ll wait for that.