0

I am trying to run the following query:

select new br.com.edipo.ada.entity.Resultado (et, avg(es.vlEscolha) as vlCalculado)
from Escolha es
join fetch Resolucao re on re.idResolucao = es.idResolucao
join fetch Alternativa al on al.idAlternativa = es.idAlternativa
join fetch Questao qu on qu.idQuestao = al.idQuestao
join fetch QuestaoEtiqueta qe on qe.idQuestao = qu.idQuestao
join fetch Etiqueta et on et.idEtiqueta = qe.idEtiqueta
where es.blSelecionada = 1
and re.idAvaliacao = :idAvaliacao
and re.idUsuario = :idUsuario
group by et.dsEtiqueta

But I am getting the following error:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: on near line 1, column 149 [select new br.com.edipo.ada.entity.Resultado (et, avg(es.vlEscolha) as vlCalculado) from br.com.edipo.ada.entity.Escolha es join fetch Resolucao re on re.idResolucao = es.idResolucao join fetch Alternativa al on al.idAlternativa = es.idAlternativa join fetch Questao qu on qu.idQuestao = al.idQuestao join fetch QuestaoEtiqueta qe on qe.idQuestao = qu.idQuestao join fetch Etiqueta et on et.idEtiqueta = qe.idEtiqueta where es.blSelecionada = 1 and re.idAvaliacao = :idAvaliacao and re.idUsuario = :idUsuario group by et.dsEtiqueta]

According to it, the error is on column 149 ("... Resolucao re ON ..."), but I cannot see what is wrong.

I am using JPA 2.0 on JBoss AS 7.

2 Answers 2

1

Indeed the problem is with ON keyword as it is not used in JPQL. Try to replace your query with:

select new br.com.edipo.ada.entity.Resultado (et,avg(es.vlEscolha) as vlCalculado)
from Escolha es
join fetch Resolucao re
join fetch Alternativa al
join fetch Questao qu
join fetch QuestaoEtiqueta qe
join fetch Etiqueta et
where es.blSelecionada = 1
and re.idAvaliacao = :idAvaliacao
and re.idUsuario = :idUsuario
group by et.dsEtiqueta
Sign up to request clarification or add additional context in comments.

Comments

0

Thanks! Here is how it ended up:

select new br.com.edipo.ada.entity.Resultado (et.dsEtiqueta,avg(es.vlEscolha) as vlCalculado)
from Escolha es
join es.resolucao re
join es.alternativa al
join al.questao qu
join qu.etiquetas et
where es.blSelecionada = 1
and re.avaliacao.id = :idAvaliacao
and re.idUsuario = :idUsuario
group by et.dsEtiqueta

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.