protected function addOrderBy(SelectStatement $selectStmt, $orderby, $orderType, $aliasName, $defaultOrder) {
    if ($orderby == null) {
      $orderby = [];
      // use default ordering
      if ($defaultOrder && sizeof($defaultOrder) > 0) {
        foreach ($defaultOrder as $orderDef) {
          $orderby[] = $orderDef['sortFieldName']." ".$orderDef['sortDirection'];
          $orderType = $orderDef['sortType'];
        }
      }
    }
    for ($i=0, $count=sizeof($orderby); $i<$count; $i++) {
      $curOrderBy = $orderby[$i];
      $orderByParts = preg_split('/ /', $curOrderBy);
      $orderAttribute = $orderByParts[0];
      $orderDirection = sizeof($orderByParts) > 1 ? $orderByParts[1] : 'ASC';
      if (strpos($orderAttribute, '.') > 0) {
        // the type is included in the attribute
        $orderAttributeParts = preg_split('/\./', $orderAttribute);
        $orderAttribute = array_pop($orderAttributeParts);
      }
      $mapper = $orderType != null ? self::getMapper($orderType) : $this;
      $orderAttributeDesc = $mapper->getAttribute($orderAttribute);
      if ($orderAttributeDesc instanceof ReferenceDescription) {
      	// add the referenced column without table name
      	$mapper = self::getMapper($orderAttributeDesc->getOtherType());
      	$orderAttributeDesc = $mapper->getAttribute($orderAttributeDesc->getOtherName());
      	$orderColumnName = $orderAttributeDesc->getColumn();
      }
      elseif ($orderAttributeDesc instanceof TransientAttributeDescription) {
      	// skip, because no column exists
      	continue;
      }
      else {
      	// add the column with table name
      	$tableName = $aliasName != null ? $aliasName : $mapper->getRealTableName();
      	$orderColumnName = $tableName.'.'.$orderAttributeDesc->getColumn();
      }
      $selectStmt->order([$orderColumnName.' '.$orderDirection]);
    }
  }