错误:
org.hibernate.hql.ast.QuerySyntaxError:意外令牌 org.hibernate.hql.ast.QuerySyntaxError:意外令牌:ON近线 1,第148列[SELECT op.username,op.email,orders.p_id,orders.o_id, product.listed_price FROM com.model.Orders命令INNER JOIN orders.OrderProcessing as op ON op.u_id = orders.u_id INNER JOIN orders.Product as product ON product.p_id = orders.p_id WHERE product.p_id ='208'ORDER BY op.username]
productList =
(List<Object[]>) session.createQuery("SELECT op.username, op.email, orders.p_id, orders.o_id, product.listed_price " +
"FROM Orders orders " +
"INNER JOIN orders.OrderProcessing as op " +
"ON op.u_id = orders.u_id " +
"INNER JOIN orders.Product as product " +
"ON product.p_id = orders.p_id " +
"WHERE product.p_id = '"+p_id +"' " +
"ORDER BY op.username").list();
答案 0 :(得分:1)
Hibernate支持加入限制,但语法与SQL不同。您必须在Hibernate中将ON
关键字替换为WITH
!
答案 1 :(得分:0)
productList = (List<Object[]>) session.createQuery("SELECT op.username, op.email, orders.p_id, orders.o_id, product.listed_price " + "FROM Orders orders " +"INNER JOIN orders.OrderProcessing as op " + "ON op.u_id = orders.u_id"+ "INNER JOIN orders.Product as product " + "ON product.p_id = orders.p_id "+ "WHERE product.p_id = '"+p_id +"'" "ORDER BY op.username").list();
您必须检查订单表。 orders.orderProcessing不是一个表,它是一个来自orders表的列。
答案 2 :(得分:0)
Chetter Hummin是对的,HQL不支持“on”。 请参阅:http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html