我有以下查询,我需要在联合表中找到元素的数量。
@NamedQueries({ @NamedQuery(name = "A.count", query = "SELECT COUNT (p.pid) FROM Pet p INNER JOIN Interaction ir ON ir.modelId = p.modelId WHERE p.modelId = :modelId")})
但是对于上面的设置,我在eclipse中得到以下3个错误。即使在服务器中部署它也会引发异常
部署时的例外情况:
15:43:37,915 ERROR [org.hibernate.hql.internal.ast.ErrorCounter] (ServerService Thread Pool -- 153) Path expected for join!: Path expected for join!
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:378) [hibernate-core-4.3.1.Final.jar:4.3.1.Final]
答案 0 :(得分:1)
查询中的语法不正确。试试这个:
SELECT COUNT (p.pid) FROM Pet INNER JOIN model.pets as p
INNER JOIN Interaction.model as model WHERE model.id = :modelId
另请看一下:
https://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html#queryhql-joins