String hql = "select new com.imooc.model.Order(o.customer.name,o.tradeDate,o.status,o.amount) "
+ " from Order as o "
+ " where o.tradeDate between '2015-05-01' and '2015-06-01' "
+ " and o.status='已发货' or o.status='已付款' "
+ " and o.amount > 1000 "
+ " order by o.status asc,o.tradeDate desc,o.amount desc";
有时候我们的实体类和某些lib中的Java类会有冲突,结果用上述HQL语句的时候就报了java.lang.ClassCastException异常。
原因:存在同名的java类,这是导致这个异常的原因之一。
解决方法:给bean加上具体路径:如 select new com.exampley.User(name,age) from com.exampley.User;
请问解决了吗
你这HQL 怎么在 new对象呀
String hql = "select Order(o.customer.name,o.tradeDate,o.status,o.amount) " + " from Order as o " + " where o.tradeDate between '2015-05-01' and '2015-06-01' " + " and o.status='已发货' or o.status='已付款' " + " and o.amount > 1000 " + " order by o.status asc,o.tradeDate desc,o.amount desc";
这样试试