1 Reply Latest reply on Mar 20, 2017 12:44 PM by jaikiran

    Session bean ejb exception handling

    dgodbey

      Example: tried to create a component where there is a non-nullable field in database. Null was sent, and the db objected and threw an exception. That's fine, except apparently the runtime engine never fell into my catch block. The caller of the method received an org.hibernate.engine.jdbc.spi.SqlException, but nowhere in the cause list of the received exception was a Report209EjbException. The caller could easily handle the exception with kind words to the user (dummy, you MUST have a releaseId on component create), but not at all straightforward in handling exception as it is currently. Am I missing something? Is there a config setting that tells Wildfly to honor catch blocks in session bean?

       

      Here is my method:

       

        public ComponentIF createComponent(ComponentIF comp, Long projectId, Long creatorId, Long releaseId, Long eventId) {

          try {

            _log.debug("******* Ejb says inside create component ");

            setComponentObjects(comp, projectId, creatorId, releaseId, eventId);

            _log.debug("******* after set component objects ");

            em.persist(comp);

          } catch (Throwable e) {

      // This comment never output, and this class not part of cause list.

            _log.error("Ejb says: "+e.getClass().getName());

            throw new Report209EjbException(e);

          }

          return comp;

        }

       

      Thanks,

      Dave

        • 1. Re: Session bean ejb exception handling
          jaikiran

          The database insert happens upon commit of the transaction that's associated with your bean method. The commit of the transaction itself happens upon the completion of the method implementation body, so it's already past that catch block.