我是新來的JPQL和掙扎了一下翻譯我的SQL來JPQL。我有一個簡單的查詢,這在MySQL的工作原理:MySQL來JPQL內加入
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
爲什麼宥調用表'ao'這裏'INNER JOIN AO ON'但在覈心的MySQL調用表'JOIN askorder ON'等什麼是真實的表名? – Alex
真正的表名是askorder。我剛剛聽到我的語法困惑。 – zobbo