private void deleteEntity(HttpServletRequest req, String entityId)
    throws ServletException, IOException {
        
        BeanCollection entityBeanList = retrieveEntityBeanList(req);
        BeanCollection subEntityBeanList = null;
        EntityBean subEntity = null;
        EntityBean entity = findEntityBeanById(entityBeanList, entityId);
        
        // check to see if the entity is a parent or a subEntity
        if (entity == null) {
            ErrorBean errorBean = new ErrorBean();
            errorBean.addError(ERROR_ID_NOTFOUND, FormError.SEVERITY_INFO);
            req.setAttribute("errorBean", errorBean);
            return;
        }
        
        // if this is a subEntity, just go ahead and delete it
        if (entity.getParentId() != EntityBean.ENTITY_TOP_LEVEL_PARENT_ID) {
            if (EntityManager.deleteEntity(entity)) {
                deleteSubEntityInSession(req, entity);
            }
        } // this is a parent Entity, so we need to delete all subEntities
        else {
            // delete the subEntities
            subEntityBeanList = entity.getSubEntities();
            if (subEntityBeanList != null && subEntityBeanList.size() > 0) {
                for (int i = 0; i < subEntityBeanList.size(); i++) {
                    subEntity = (EntityBean) subEntityBeanList.getItem(i);
                    if (EntityManager.deleteEntity(subEntity)) {
                        deleteSubEntityInSession(req, subEntity);
                    }
                }
            }
            // delete the parent
            if (EntityManager.deleteEntity(entity)) {
                deleteEntityInSession(req, entity);
            }
        }
    }