3 Replies Latest reply on Oct 3, 2002 7:28 AM by Sergei Batiuk

    Wrong exception is thrown during entity's ejbCreate()

    Sergei Batiuk Newbie

      Hello,

      My env:

      JBoss-3.0.2_Tomcat_4.0.4
      JDK 1.4
      Win2000


      I have developed two ejbs: a sesson bean, DepartmentManager, and an entity bean, Department. DepartmentManager is responsible for creating new Departments:

      public void createDepartment( DepartmentData dd ) throws DeptSysException, ValidateException {
      try {
      Context ctx = new InitialContext();
      DepartmentHome deptHome = ( DepartmentHome )ctx.lookup( "java:comp/env/ejb/Department" );
      deptHome.create( dd );
      }
      catch( ValidateException ex ) {
      throw ex;
      }
      catch( Exception ex ) {
      throw new DeptSysException( ex.toString(), ex );
      }
      }

      the Department's ejbCreate() method first validates the supplied data and throws ValidateException if data is not valid, and then fills the fields with appropriate values.
      DeparmentHome interface looks like:

      public interface DepartmentHome extends EJBLocalHome {
      public Department create( DepartmentData dd ) throws CreateException, ValidateException;
      public Department findByPrimaryKey( Integer pk ) throws FinderException;
      }


      ejbCreate() method for the DepartmentBean:

      public class DepartmentBean implements EntityBean {
      ..

      public Integer ejbCreate(DepartmentData dd) throws CreateException, ValidateException {
      try {
      validate();
      this.setData( dd );
      return null;

      }
      catch( Exception ex ) {
      throw new CreateException( ex.toString() );
      }
      }
      ..
      }

      the validate() method throws ValidateException if validation fails. However, the exception caught by DepartmentManager is not ValidateException, as expected, but javax.ejb.EJBException instead:

      javax.ejb.EJBException: RuntimeException; CausedByException is:
      javax.ejb.CreateException: bsv.depfunc.ejb.ValidateException: Validation failed

      The ValidateException still appears on the screen, but it seems to be wrapped within EJBException. It looks like javax.ejb.EJBException to the DepartmentManager, not ValidateException.


      What am I doing wrong? How do I force ejbCreate() throw ValidateException, so that DepartmentManager could catch it, without EJBException?