public static boolean lookupAllEntities(BeanCollection entities) {
      ////
      System.out.println("in EntityManager: lookupAllContacts....");
      ////
      boolean good = true;

      try {
         ResultSet rset = null;
         PreparedStatement stmt = null;

         String statementName = "lookupEntities";
         SQLConnManager connMgr = new SQLConnManager(statementName, new ErrorBean());
         EntityBean entity = null;
         BeanCollection altSpellings = null;
         BeanCollection subEntities = null;

         try {
            // Get database connection
            if ((connMgr.getConn()) == null) {
               good = false;
            }
            else {
               stmt = connMgr.loadPreparedStatement(statementName);
               rset = stmt.executeQuery();

               int prevParentId = -1;

               // note:
               // in order for entities to be populated correctly,
               // the resultset being ordered by parentId (handled in sql stmt)
               while (rset.next()) {
                  // populate values in a new EntityBean
                  entity = new EntityBean();
                  entity.setEntityId(rset.getInt(1));
                  entity.setParentId(rset.getInt(2));
                  entity.setName(rset.getString(3));
                  entity.setActive(rset.getInt(4) == 1);
                  entity.setNote(rset.getString(5));
                  entity.setPhoneNumber(rset.getString(6));
                  entity.setAudioName(rset.getString(7));
                  //add the altSpellings
                  altSpellings = new BeanCollection();
                  AltSpellingManager.lookupAltSpellingByOwner(entity.getEntityId(), EntityBean.ENTITY_TYPE_ID, altSpellings);
                  entity.setAltSpellings(altSpellings);

                  if(entity.getParentId() != 0) {
                     //this is a subEntity,
                     // - if the parentId is different from the previous,
                     //      create a new subentity bean collection
                     //      and update the value of prevParentId
                     //
                     // - add to the current subentity bean collection
                     if(entity.getParentId() != prevParentId) {
                        if(prevParentId != -1) {
                           addSubEntities(entities, prevParentId, subEntities);
                        }
                        prevParentId = entity.getParentId();
                        subEntities = new BeanCollection();
                     }
                     subEntities.addItem(entity);
                     if(rset.isLast()) {
                        addSubEntities(entities, prevParentId, subEntities);
                     }
                  }

                  //
                  entities.addItem(entity);
               }
            }
         }
         catch (Exception e) {
            good = false;
            ////e.printStackTrace(System.err);
            UtilBundle.log.logMessage(e, statementName, LogUtil.SEVERE);
         }
         // Free resources allocated.
         connMgr.shutDown(true);
      }
      catch (Exception e) {
         good=false;
         ////e.printStackTrace(System.err);
      }
      return good;
   }