获取错误嵌套异常是org.hibernate.QueryException:无法解析属性:compositKey:

时间:2013-02-11 08:44:07

标签: hibernate

我收到错误

nested exception is org.hibernate.QueryException: could not resolve property: 
compositKey of: com.thetasp.tu.data.TuSegCreditExposure 
[from com.thetasp.tu.data.TuSegCreditExposure c where c.compositKey.rptRefNo=? and 
c.ic=?]

这里我正在进行查询并获得异常

public List<Object> findSegObjByRptRefNo(String rptRefNo, Class className,
        String[] fields, String[] values) {
    StringBuffer buff = new StringBuffer();
    String sql = "from " + className.getName() + " c 
        where c.compositKey.rptRefNo=?";
    buff.append(sql);

    if (fields != null) {
        for (int i = 0; i < fields.length; i++) {
            String field = fields[i];
            buff.append(" and c." + field + "=?");
        }
    }

    Object[] argument = new Object[values.length + 1];
    argument[0] = rptRefNo;

    for (int i = 1; i <= values.length; i++) {
        argument[i] = values[i - 1];
        System.out.println(argument[i]);
    }

    try {

        List<TuSegCreditExposure> exList = getHibernateTemplate().find(
                buff.toString(), argument);
    } catch (Exception e) {
        String message = e.getMessage();
        System.out.println(e.getStackTrace());
    }

    return getHibernateTemplate().find(buff.toString(), argument);
}

此行给出了错误

List<TuSegCreditExposure> exList = getHibernateTemplate().find(buff.toString(), 
                                                       argument);

为什么我收到此错误。

这是我的TuSegCreditExposueclass

public class TuSegCreditExposure extends AbstractArchivableObj implements Serializable {

private TuSegCompositeKey compositeKey;
private String totalAccountsRevolv;
    ....

}

请告诉我为什么我得到这个例外。我做错了什么?

由于

1 个答案:

答案 0 :(得分:0)

应该是

String sql = "from " + className.getName() + " c 
    where c.compositeKey.rptRefNo=?";

而不是compositKey,请参阅composit中缺少的e:)

由于