首先我的设置:
- mysql-connector-java 5.1.24
- 休眠核心 4.1.10.Final
运行此条件查询时出现 ClassCastException :
Criteria sellableItemsCriteria = session.createCriteria(MarketData.class, "md");
sellableItemsCriteria.add(Restrictions.in("region", regions));
sellableItemsCriteria.add(Restrictions.in("itemTypeId", items));
DetachedCriteria sellOrderSizeCriteria = DetachedCriteria.forClass(MarketOrder.class);
sellOrderSizeCriteria.add(Restrictions.eq("marketDataId", "md.id"));
sellOrderSizeCriteria.add(Restrictions.eq("bid", false));
sellOrderSizeCriteria.setProjection(Projections.count("marketDataId"));
sellableItemsCriteria.add(Subqueries.lt(0L, sellOrderSizeCriteria));
例外:
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
问题出在这一行(首先我尝试使用 0 而不是 0L 并且我得到 Integer cannot be cast to Long 所以我切换到 Long):
sellableItemsCriteria.add(Subqueries.lt(0L, sellOrderSizeCriteria));
这是我要运行的 mysql 查询:
SELECT md.* FROM `marketdata` md
WHERE md.region IN (:regions)
AND md.item_typeID IN (:items)
AND (SELECT COUNT(marketData_id) FROM `marketorder` WHERE marketData_id = md.id AND bid = 0) > 0
如何解决演员阵容问题?
或者也许有更好的方法可以用 Criteria 做到这一点?
谢谢