Join fetch: “la requête spécifiée chargement par jointure ouverte, mais le propriétaire de l'extraites de l'association n'était pas présent dans la liste de sélection”

J'ai un code suivant:

public class ValueDAO  implements BusinessObject<Long> {

    private Long id;
    private String code;
    private ClassDAO classDAO ;
        ....
}

public List<String> getCodesByCodeClass(Long classId) {
    String select = "select distinct val.code from ValueDAO val left " +
        "join fetch val.classDAO ";
    String where = "where val.classDAO.id = ? order by val.code";

    return getHibernateTemplate().find(select + where, classId);
}

Il soulève une exception:

 org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list

Dans le résultat, je wan pour obtenir uniquement les codes.

OriginalL'auteur yons88 | 2012-09-19