嗨,我是openbravo初學者。我想知道從HQL查詢結果集返回的對象。通常我可以返回列表或字符串。當我試圖返回對象它的顯示錯誤就像不能將對象轉換爲字符串。如何在Openbravo中使用HQL查詢結果集返回對象
這裏我的目標是:ShipmentInOut
private ShipmentInOut getShipment(String documentNo) {
String query = "select id from MaterialMgmtShipmentInOut where documentNo='" + documentNo
+ "' and salesTransaction='Y'";
Query resultset = OBDal.getInstance().getSession().createQuery(query);
List<ShipmentInOut> shpmntCritList = resultset.list();
if (shpmntCritList != null && shpmntCritList.size() > 0) {
return shpmntCritList.get(0);
} else {
throw new OBException("shipment " + documentNo + " not found");
}
}
在上面statment我有例外,所以我決定做標準查詢和我寫的條件查詢equalent上面HQL查詢,但不幸的是,如果條件第二部分返回0爲 的結果。但我不知道爲什麼我在同一種查詢中得到不同的結果。上面的HQL查詢正確輸入if條件。但問題是鑄造。
private ShipmentInOut getShipment(String documentNo) {
log.info()
OBCriteria<ShipmentInOut> shpmntCrit = OBDal.getInstance().createCriteria(ShipmentInOut.class);
shpmntCrit.add(Restrictions.eq(ShipmentInOut.PROPERTY_DOCUMENTNO, documentNo));
shpmntCrit.add(Restrictions.eq(ShipmentInOut.PROPERTY_SALESTRANSACTION, true));
List<ShipmentInOut> shpmntCritList = shpmntCrit.list();
if (shpmntCritList != null && shpmntCritList.size() > 0) {
return shpmntCritList.get(0);
} else {
throw new OBException("shipment " + documentNo + " not found");
}
}
請任何人幫助我。我想實現上述任何一種方法。在此先感謝
您還沒有提供類映射 – carbontax 2014-11-23 22:04:27
HQL應該明確地返回對象。你在哪一行出錯? – 2014-11-25 04:57:20