我是JPQL的新手,并且正在努力将我的SQL翻译成JPQL。我有一个简单的查询,适用于MYSQL:
SELECT askorder.price, bidorder.price from OrderBook JOIN askorder
ON OrderBook.ASKORDERID_ORDERID = askorder.ORDERID
JOIN bidorder ON OrderBook.BIDORDERID_ORDERID = bidorder.ORDERID
WHERE askorder.ORDERID = 2;
我试图将其转换为JPQL,但我确定它错了。具体来说,我认为它可能是ON关键字,我不知道如何将其转换为JPQL:
@NamedQuery(
name="findOrderBooksPrices",
query="SELECT ao.price, bo.price from OrderBook bo, OrderBook ao" +
"INNER JOIN ao ON bo.ASKORDERID_ORDERID = ao.ORDERID " +
"INNER JOIN bo ON OrderBook.BIDORDERID_ORDERID = bo.ORDERID " +
"WHERE ao.ORDERID = :askOrderId"
)
我得到的错误是:
Internal Exception: Exception [EclipseLink-7158] (Eclipse Persistence
Services - 2.5.0.v20130507-3faac2b):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: Error encountered when building the @NamedQuery
[findOrderBooksPrices] from entity class [class
org.eclipse.persistence.internal.jpa.metadata.queries.
NamedQueryMetadata].Internal Exception: java.lang.ClassCastException:
org.eclipse.persistence.jpa.jpql.parser.NullExpression cannot be cast to
org.eclipse.persistence.jpa.jpql.parser.IdentificationVariable. Please
see server.log for more details.
我希望在提交订单ID后从每个订单表中返回价格。
谢谢你的期待。 干杯, Zerb
答案 0 :(得分:0)
只是一个猜测:
query="SELECT ao.price, bo.price FROM OrderBook " +
"INNER JOIN askorder ao " +
"INNER JOIN bidorder bo " +
"WHERE ao.ORDERID = :askOrderId"