zbig zbig - 4 days ago 5
Java Question

Hibernate expecting "all", found 'JOIN'

I'm getting

QuerySyntaxException: expecting "all", found 'JOIN' near line 1, column 50 [SELECT p FROM com.rr.model.Person p FETCH JOIN p.positions pos WHERE p.id=:id]


exception with Hibernate. Changing 'JOIN' to 'ALL' does not help and produce following error:

QuerySyntaxException: expecting "properties", found 'p' near line 1, column 54 [SELECT p FROM com.rr.model.Person p FETCH ALL p.positions pos WHERE p.id=:id]


What's going on and how the correct query should look like?

Answer

The problem is I switched syntax to 'FETCH JOIN' form the correct one: 'JOIN FETCH'. The correct query should look like this

 SELECT p FROM Person p JOIN FETCH p.positions pos WHERE p.id=:id

The correct syntax with 'ALL' looks like this:

SELECT p FROM Person p FETCH ALL PROPERTIES WHERE p.id=:id
Comments