2

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;
    }
}
6
  • Could you please show your Order entity. Commented Apr 6, 2020 at 8:13
  • And what hibernate dialect do you use? Commented Apr 6, 2020 at 8:14
  • added the entity Commented Apr 6, 2020 at 8:21
  • org.hibernate.dialect.MySQL5InnoDBDialect Commented Apr 6, 2020 at 8:23
  • One more question, what MySQL version do you use? Commented Apr 6, 2020 at 8:25

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.