@Override
 public int compare(RowKey key1, RowKey key2) {
   CompareToBuilder builder = new CompareToBuilder();
   for (String name : sortFields) {
     builder.append(key1.getColumnValue(name), key2.getColumnValue(name));
   }
   return builder.toComparison();
 }
  /**
   * Returns the entity key on the other side of association row represented by the given row key.
   *
   * <p><b>Note:</b> May only be invoked if the row key actually contains all the columns making up
   * that entity key. Specifically, it may <b>not</b> be invoked if the association has index
   * columns (maps, ordered collections), as the entity key columns will not be part of the row key
   * in this case.
   */
  private EntityKey getEntityKey(AssociationKey associationKey, RowKey rowKey) {
    String[] associationKeyColumns =
        associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns();
    Object[] columnValues = new Object[associationKeyColumns.length];
    int i = 0;

    for (String associationKeyColumn : associationKeyColumns) {
      columnValues[i] = rowKey.getColumnValue(associationKeyColumn);
      i++;
    }

    EntityKeyMetadata entityKeyMetadata =
        associationKey.getMetadata().getAssociatedEntityKeyMetadata().getEntityKeyMetadata();
    return new EntityKey(entityKeyMetadata, columnValues);
  }