2013-02-11 76 views
0

我收到错误得到错误嵌套的例外是org.hibernate.QueryException:无法解析属性:compositKey的:

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; 
    .... 

}

请告诉我为什么我收到此异常。我做错了什么?

感谢

+0

你尝试调试代码是什么'c.id '在错误信息中。它在桌子上吗? – Prateek 2013-02-11 08:45:59

+0

@pKs'c.id'或'c.ic'? – Basit 2013-02-11 08:47:41

+0

错字,我的意思是c.ic? – Prateek 2013-02-11 08:49:27

回答

0

应该

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

而非compositKey,看到失踪E在composit :)

感谢

相关问题