Changeset 3777


Ignore:
Timestamp:
Sep 25, 2007, 11:35:01 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #785: ItemContext?.configureQuery() should use fetch join if a non-selected column is used in ORDER BY

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.4-stable/src/core/net/sf/basedb/core/ItemContext.java

    r3679 r3777  
    898898    // Tempoarary storage for all associations that must be left joined
    899899    Set<String> leftJoins = autoLeftJoin ? new HashSet<String>() : null;
     900    Set<String> sortedProperties = autoLeftJoin ? new HashSet<String>() : null;
    900901   
    901902    // Add sort order information
     
    930931          if (dotIndex >= 0)
    931932          {
    932             leftJoins.add(sortProperty.substring(0, dotIndex));
     933            String toJoin = sortProperty.substring(0, dotIndex);
     934            leftJoins.add(toJoin);
     935            sortedProperties.add(toJoin);
    933936          }
    934937        }
     
    995998    {
    996999      int i = 0;
     1000      // Use fetch joins for columns appearing in the ORDER BY clause
     1001      // if the query is distinct and the database requires it
     1002      boolean selectOrderBy = query.isDistinct() &&
     1003        HibernateUtil.getDbEngine().selectOrderByColumnsIfDistinct();
    9971004      for (String property : leftJoins)
    9981005      {
     1006        boolean fetch = selectOrderBy && sortedProperties.contains(property);
    9991007        if (property.startsWith("@")) property = property.substring(1);
    10001008        i++;
    1001         query.join(Hql.leftJoin(property, "alj"+i));
     1009        query.join(Hql.leftJoin(null, property, "alj"+i, null, fetch));
    10021010      }
    10031011    }
Note: See TracChangeset for help on using the changeset viewer.