sk17261205
sk17261205

Reputation: 451

ClassCastException: org.hibernate.hql.internal.ast.tree.SqlNode cannot be cast to org.hibernate.hql.internal.ast.tree.PathNode

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;
    }
}

Upvotes: 2

Views: 250

Answers (1)

Eklavya
Eklavya

Reputation: 18480

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);

Upvotes: 2

Related Questions