英文:
ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to 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;
}
}
英文:
I have service which connects to maria db in order to fetch data. I have the following method in my repository to fetch order data:
@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);
When I try to start the service, it throws me following error:
ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.PathNode
Any ideas on how to fix this? Appreciate the help.
Entity:
@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;
}
}
答案1
得分: 2
在@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);
英文:
Use full reference(with the package name) of your class in @Query
.
Suppose your Order
class is in your com.earth.project
package then query will be
@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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论