dinesh707
dinesh707

Reputation: 12582

@NamedQuery INNER JOIN does not work

I have the following query where i need to find the count of elements in a joint tables.

@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")})

But for the above setup i get the following 3 errors in eclipse. Even deploying it in server throws an exception

Exception on deployment :

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]

Upvotes: 1

Views: 2740

Answers (1)

Genzotto
Genzotto

Reputation: 1974

The syntax in your query is not correct. Try this:

SELECT COUNT (p.pid) FROM Pet INNER JOIN model.pets as p 
INNER JOIN Interaction.model as model WHERE model.id = :modelId

Also take a look at this:

https://docs.jboss.org/hibernate/core/3.5/reference/en/html/queryhql.html#queryhql-joins

Upvotes: 1

Related Questions