Hibernate 的 SqlNode cannot be PathNode 异常
错误代码:org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.PathNode
该异常通常是在Hibernate中使用HQL查询语言时出错:
一般从数据库中获得的字段: 没有错误
String hql="select o.userName,o.pId,o.quantity,o.buyTime,p.pName,p.pSalePrice "
+ " from Order o,Products p "
+ "where o.pId=p.pId and o.order_id='"+this.order_id+"'";
如果对获得字段进行封装:会报错
String hql="select distinct new Order</span>(o.userName,o.pId,o.quantity,o.buyTime,p.pName,p.pSalePrice) "
+ " from Order o,Products p "
+ "where o.pId=p.pId and o.order_id='"+this.order_id+"'";
就这个 [ org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.PathNode ]
原因:Hibernate对HQL查询语言进行转换后与sql不对应或找不到具体的类与之对应
解决办法:在封装的字段的类前加上类所在的包名:
String hql="select distinct new com.po.Order(o.userName,o.pId,o.quantity,o.buyTime,p.pName,p.pSalePrice) " + " from Order o,Products p " + "where o.pId=p.pId and o.order_id='"+this.order_id+"'";