Reputation: 229
I don't see where is the error.
This is query:
@NamedQuery(name = Sustitutos.Q_BUSCAR_SUSTITUTOS_OFICINA,
query = "select e from Sustitutos e inner join Personas p ON p.codPersona = e.sustituido WHERE p.codUnidad = :codigo"),
And I call it in this way:
Query q = this.em.createNamedQuery(Sustitutos.Q_BUSCAR_SUSTITUTOS_ZONA);
q.setParameter("codigo", codUnidadSup);
List<Sustitutos> resultado = q.getResultList();
The stack trace:
Error in named query: Sustitutos.buscarSustitutosOficina
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ON near line
1, column 83 [select e from com.bs.proteo.channel.arc.entity.Sustitutos e
inner join Personas p ON p.codPersona = e.sustituido WHERE p.codUnidad =
:codigo]
What I'm doing wrong? Thanks
Upvotes: 1
Views: 852
Reputation: 3466
There is no "ON"
in JPQL
, but you can do an implicit join and use the WHERE
clause.
@NamedQuery(name = Sustitutos.Q_BUSCAR_SUSTITUTOS_OFICINA,
query = "select e from Sustitutos e join e.personas p WHERE p.codUnidad = :codigo"),
Upvotes: 1
Reputation: 32145
As you can see it in the Stack trace the problem is with the ON
keyword.
It's an SQL keyword and it's not recognized in JPQL, and as stated in comments you should join the object reference with JOIN
.
This is how your query should be:
query = "select e from Sustitutos e join e.personas p WHERE p.codUnidad = :codigo")
Upvotes: 1