Naanavanalla
Naanavanalla

Reputation: 1522

Multiple inner joins in JPQL

I have been trying to write a jpql query, but getting the exception,

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [SELECT * FROM com.highpeak.tlp.datastore.model.TaskRequestModel trm inner join trm.task t inner join trm.task.matterId m inner join trm.task.matterId.client c where trm.isActive is true and trm.task.isActive is true and trm.task.matterId.isActive is true and trm.task.matterId.client.isActive is true trm.requestedFor =:owner order by trm.createdAt DESC]

My query is

SELECT * FROM TaskRequestModel trm inner join trm.task t 
inner join trm.task.matterId m inner join trm.task.matterId.client c 
where trm.isActive is true and trm.task.isActive is true and 
trm.task.matterId.isActive is true and 
trm.task.matterId.client.isActive is true trm.requestedFor =:owner 
 order by trm.createdAt DESC"

What might be the issue?

Update I even tried

SELECT * FROM TaskRequestModel trm inner join trm.task t inner join 
t.matterId m inner join m.client c where trm.isActive is true and 
t.isActive is true and m.isActive is true and c.isActive is true and 
trm.requestedFor =:owner  order by trm.createdAt DESC

Upvotes: 0

Views: 1025

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522762

I'm not sure that is true is valid JPQL (it's certainly not valid SQL). So you should be just asserting columns directly in your WHERE clause if they be boolean. Besides this, you were also missing an AND in the WHERE clause. Putting this all together, and removing the incorrect GROUP BY clause gives this:

SELECT *
FROM TaskRequestModel trm
JOIN trm.task t 
JOIN trm.task.matterId m
JOIN trm.task.matterId.client c 
WHERE
    trm.isActive AND
    trm.task.isActive AND 
    trm.task.matterId.isActive AND
    trm.task.matterId.client.isActive AND
    trm.requestedFor =:owner 
ORDER BY trm.createdAt DESC

Upvotes: 2

Related Questions