【发布时间】:2016-11-02 21:40:31
【问题描述】:
Getting QuerySyntaxException 试图运行这个查询:
public interface SignalRepository extends PagingAndSortingRepository<Signal, Long> {
...
@Query("select p1 from Signal p1 LEFT JOIN Signal p2 "
+ " ON (p1.zoneId = p2.zoneId AND p1.createdAt < p2.createdAt) "
+ " where p2.id is null AND p1.userId=?#{[0]} AND p1.pid=?#{[1]}")
产生这个错误:
caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [select p1 from com.newco.models.Signal p1 LEFT JOIN Signal p2 ON (p1.zoneId = p2.zoneId AND p1.createdAt < p2.createdAt) where p2.id is null AND p1.userId=?1 AND p1.pid=?2]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:268) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
当键入 SQL 命令行(和 Ruby on Rails)时,此查询运行良好,但在 Spring/JAP 中失败。
【问题讨论】:
-
JPQL != SQL ...
标签: java spring hibernate spring-mvc jpa