嗨,我是 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");
}
}
在上面的语句中,我遇到了异常,所以我决定进行条件查询,我编写了与上述 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");
}
}
请任何人帮助我。我想实现上述任何一种方法。提前致谢