Program: 67866
Project: 67866
Buggy source:
/** 
 * INTERNAL: Process an order by value (if specified) for the given collection  mapping. Order by specifies the ordering of the elements of a collection  valued association at the point when the association is retrieved. The syntax of the value ordering element is an orderby_list, as follows: orderby_list ::= orderby_item [, orderby_item] orderby_item ::= property_or_field_name [ASC | DESC] When ASC or DESC is not specified, ASC is assumed. If the ordering element is not specified, ordering by the primary key of the associated entity is assumed. The property or field name must correspond to that of a persistent property or field of the associated class. The properties or fields  used in the ordering must correspond to columns for which comparison operators are supported.
 */
protected void processOrderBy(CollectionMapping mapping){
  if (m_orderBy != null) {
    MetadataDescriptor referenceDescriptor=getReferenceDescriptor();
    if (m_orderBy.equals("String_Node_Str")) {
      List<String> orderByAttributes=referenceDescriptor.getIdOrderByAttributeNames();
      if (referenceDescriptor.hasEmbeddedIdAttribute()) {
        String embeddedIdAttributeName=referenceDescriptor.getEmbeddedIdAttributeName();
        for (        String orderByAttribute : orderByAttributes) {
          mapping.addAggregateOrderBy(embeddedIdAttributeName,orderByAttribute,false);
        }
      }
 else {
        for (        String orderByAttribute : orderByAttributes) {
          mapping.addOrderBy(orderByAttribute,false);
        }
      }
    }
 else {
      StringTokenizer commaTokenizer=new StringTokenizer(m_orderBy,"String_Node_Str");
      while (commaTokenizer.hasMoreTokens()) {
        StringTokenizer spaceTokenizer=new StringTokenizer(commaTokenizer.nextToken());
        String propertyOrFieldName=spaceTokenizer.nextToken();
        MappingAccessor referenceAccessor=referenceDescriptor.getAccessorFor(propertyOrFieldName);
        if (referenceAccessor == null) {
          throw ValidationException.invalidOrderByValue(propertyOrFieldName,referenceDescriptor.getJavaClass(),getAccessibleObjectName(),getJavaClass());
        }
        String attributeName=referenceAccessor.getAttributeName();
        String ordering=(spaceTokenizer.hasMoreTokens()) ? spaceTokenizer.nextToken() : ASCENDING;
        if (referenceAccessor.isEmbedded()) {
          for (          String orderByAttributeName : referenceDescriptor.getOrderByAttributeNames()) {
            mapping.addAggregateOrderBy(attributeName,orderByAttributeName,ordering.equals(DESCENDING));
          }
        }
 else {
          mapping.addOrderBy(attributeName,ordering.equals(DESCENDING));
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL: Process an order by value (if specified) for the given collection  mapping. Order by specifies the ordering of the elements of a collection  valued association at the point when the association is retrieved. The syntax of the value ordering element is an orderby_list, as follows: orderby_list ::= orderby_item [, orderby_item] orderby_item ::= property_or_field_name [ASC | DESC] When ASC or DESC is not specified, ASC is assumed. If the ordering element is not specified, ordering by the primary key of the associated entity is assumed. The property or field name must correspond to that of a persistent property or field of the associated class. The properties or fields  used in the ordering must correspond to columns for which comparison operators are supported.
 */
protected void processOrderBy(CollectionMapping mapping){
  if (m_orderBy != null) {
    MetadataDescriptor referenceDescriptor=getReferenceDescriptor();
    if (m_orderBy.equals("String_Node_Str")) {
      List<String> orderByAttributes=referenceDescriptor.getIdOrderByAttributeNames();
      if (referenceDescriptor.hasEmbeddedIdAttribute()) {
        String embeddedIdAttributeName=referenceDescriptor.getEmbeddedIdAttributeName();
        for (        String orderByAttribute : orderByAttributes) {
          mapping.addAggregateOrderBy(embeddedIdAttributeName,orderByAttribute,false);
        }
      }
 else {
        for (        String orderByAttribute : orderByAttributes) {
          mapping.addOrderBy(orderByAttribute,false);
        }
      }
    }
 else {
      StringTokenizer commaTokenizer=new StringTokenizer(m_orderBy,"String_Node_Str");
      while (commaTokenizer.hasMoreTokens()) {
        StringTokenizer spaceTokenizer=new StringTokenizer(commaTokenizer.nextToken());
        String propertyOrFieldName=spaceTokenizer.nextToken();
        MappingAccessor referenceAccessor=referenceDescriptor.getAccessorFor(propertyOrFieldName);
        if (referenceAccessor == null) {
          throw ValidationException.invalidOrderByValue(propertyOrFieldName,referenceDescriptor.getJavaClass(),getAccessibleObjectName(),getJavaClass());
        }
        String attributeName=referenceAccessor.getAttributeName();
        String ordering=(spaceTokenizer.hasMoreTokens()) ? spaceTokenizer.nextToken() : ASCENDING;
        if (referenceAccessor.isEmbedded()) {
          for (          String orderByAttributeName : referenceDescriptor.getOrderByAttributeNames()) {
            mapping.addAggregateOrderBy(m_orderBy,orderByAttributeName,ordering.equals(DESCENDING));
          }
        }
 else         if (referenceAccessor.getClassAccessor().isEmbeddableAccessor()) {
          String embeddableChain=m_orderBy;
          if (embeddableChain.contains("String_Node_Str")) {
            embeddableChain=embeddableChain.substring(0,embeddableChain.lastIndexOf("String_Node_Str"));
          }
          mapping.addAggregateOrderBy(embeddableChain,attributeName,ordering.equals(DESCENDING));
        }
 else {
          mapping.addOrderBy(attributeName,ordering.equals(DESCENDING));
        }
      }
    }
  }
}