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 并在查询中使用它。
最后一行给了我一个错误:
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.
最佳答案
看起来就像你犯了错误。
您的模式中是否有表t
?如果不是,您应该指定表名称而不是别名。
String query = "select t from myTable t where t.idOne = " + myId
+ " AND t.idTwo = " + myIdTwo
+ " AND t.idThree = " + myIdThree
+ "AND t.idFour = (select max(st.idFour) from myTable st)";
关于java - 无法在JPA中进行子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41700586/