java.sql.SQLException: Column '**' not found.
最近發現一個很不明所以的錯誤:java.sql.SQLException: Column '**' not found.
起因是:
List list = this.getHibernateTemplate().executeFind(
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {System.out.println("***in");
String hql = "select count(*) from _trading_record t where t.itemId = '" + id + "' and t.zoneCode='" + zoneCode + "'";
SQLQuery query = session.createSQLQuery(hql);
query.addEntity("t", TradingRecord.class);
return query.list();
}
});
問題:
標紅那句加上後,查詢結果便必須包含TradingRecord實體類的所有屬性,否則系統會認為返回缺失
解決:
去掉 query.addEntity("t", TradingRecord.class);