String query = "select t from myTable t where t.idOne = " + myId
+ " AND t.idTwo = " + myIdTwo
+ " AND t.idThree = " + myIdThree
+ "AND t.idFour = (select max(t.idFour) from t)";
因此myTable有一個列,我需要從查詢中獲取MAX id並將其用於查詢。無法在JPA中進行子查詢
最後一行給我一個錯誤:
Error while running query: An exception occurred while creating a query in EntityManager:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing [query from above]. [214, 214] An identification variable must be provided for a range variable declaration.
這是JPQL還是SQL?因爲'myTable'實際上應該是JPQL中的'MyEntity'(實體類的名稱)。 – SJuan76
對不起它的jpql,你是對的,它是實體類的名稱,我只是這樣命名的 –
這不正是你問你的問題,但(用正確的'ORDER BY'子句)會給你結果你想要的:http://stackoverflow.com/questions/6708085/select-top-1-result-using-jpa – SJuan76