java - ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode 不能转换为 org.hibernate.hql.internal.ast.tree.PathNode
问题描述
我有连接到 maria db 以获取数据的服务。我的存储库中有以下方法来获取订单数据:
@Query("select new Order(o.orderNumber, coalesce(o.orderId, ''), coalesce(o.env, ''), coalesce(o.poNumber, ''), coalesce(o.qty, ''), coalesce(o.sku, ''), "
+ " coalesce(o.customerNumber, ''), coalesce(o.portfolio, ''), coalesce(o.custEmail, '')) "
+ "from Order o where o.portfolio=?1 order by o.orderNumber desc")
public List<Order> findAllOrder(String portfolio);
当我尝试启动服务时,它会抛出以下错误:
ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.PathNode
有想法该怎么解决这个吗?感谢帮助。
实体:
@Entity
@Table(name = "orders")
public class Order {
private Long orderNumber;
private String orderId;
private String env;
private String poNumber;
private String qty;
private String orderItem;
private String sku;
private String status;
private String portfolio;
private Long customerNumber;
private int requestId;
private int recordId;
private String custEmail;
public Order(Long orderNumber, String orderId, String env, String poNumber, String qty, String sku,
Long customerNumber, String portfolio, String custEmail) {
this.orderNumber = orderNumber;
this.orderId = orderId;
this.env = env;
this.poNumber = poNumber;
this.qty = qty;
this.sku = sku;
this.customerNumber = customerNumber;
this.portfolio = portfolio;
this.custEmail = custEmail;
}
}
解决方案
在@Query
.
假设您的Order
课程在您的com.earth.project
包中,那么查询将是
@Query("select new com.earth.project.Order(o.orderNumber, coalesce(o.orderId, ''), coalesce(o.env, ''), coalesce(o.poNumber, ''), coalesce(o.qty, ''), coalesce(o.sku, ''), "
+ " coalesce(o.customerNumber, ''), coalesce(o.portfolio, ''), coalesce(o.custEmail, '')) "
+ "from Order o where o.portfolio=?1 order by o.orderNumber desc")
public List<Order> findAllOrder(String portfolio);
推荐阅读
- angular - 如何获得有序的嵌套承诺Angular 9
- ios - iOS 使用 Codemagic 构建失败 [适用于 Xcode]
- swift - 基于范围的 for 循环与传统的 c 风格 for 循环相比有什么好处?
- c++ - TCP 高 CPU 多客户端服务器
- asp.net-core - 不应为已部署的应用程序 / ASPNETCORE_ENVIRONMENT 启用开发环境
- python - 在 Python 中使用 Selenium 时,我总是收到“弃用警告”
- arrays - 合并数组值 - vuejs
- sql-server - SSIS OLE DB 源从 Oracle 数据源中随机丢失行
- r - 如何分隔不同列中的多项选择短语(谷歌表单)?
- anylogic - 如何编写一个 for 循环来获取整个表的信息