e = (e.getCause() == null || !(e instanceof Exception)) ? e : (Exception)e.getCause();
    public static Integer getNextCount(EJBLocalHome home) throws EJBException {        // use reflection to invoke findByPrimaryKey        Class c = home.getClass();        try {            Method m = c.getDeclaredMethod("findByPrimaryKey", new Class[]{ Integer.class } );            int maxAttempts = 10;            while (maxAttempts >= 0){                Integer id = getNextInt();                try {                    m.invoke(home, new Object[]{ id });                } catch (InvocationTargetException e){                    // if there is a finder exception it means there is no object with that key                    // and thus that the slot is free.                    if (e.getCause() instanceof FinderException){                        return id;                    }                    throw e;                }                maxAttempts--;            }        } catch (Exception e){            e = (e.getCause() == null || !(e instanceof Exception)) ? e : (Exception)e.getCause();            throw new EJBException(e);        }        throw new EJBException("Failed to generate a unique id for home " + home.getClass().getName());    }