【发布时间】:2014-04-22 13:27:18
【问题描述】:
我有一个 StockItem 类,它的字段是 Warehouse 对象。我想运行 Ebean 查询以查找某个仓库中的所有 StockItem:
List<StockItem> result = StockItem.find()
.where()
.eq("warehouse", warehouse)
.findList();
但是,结果总是大小为 0,即使在给定 Warehouse 的数据库中有 StockItems 时也是如此。我在 Warehouse 类中覆盖了 equals() 。
如果我查询所有 StockItems 的列表,然后测试仓库字段的相等性,我可以找到我正在寻找的仓库:
String resultString;
List<StockItem> result = StockItem.find().findList();
if(result.get(0).warehouse.equals(warehouse)) {
resultString = "success";
}
这是唯一的方法吗?
编辑:这是我在仓库中的 equals()
@Override
public boolean equals(Object o) {
if(o instanceof Warehouse) {
Warehouse other = (Warehouse)o;
return name.equals(other.name) && address.equals(other.address);
} else {
return false;
}
}
【问题讨论】:
-
请向您展示仓库中已覆盖的等号
-
您应该启用 Ebean 的语句日志记录来调试您在 DB GUI 中的问题