JPQL查询语法异常

时间:2014-04-28 22:25:32

标签: jpa-2.0

我正在尝试运行以下查询:

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

但是我收到以下错误:

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]

根据它,错误发生在第149栏("... Resolucao re ON ..."),但我看不出有什么问题。

我在JBoss AS 7上使用JPA 2.0。

2 个答案:

答案 0 :(得分:1)

确实问题出在ON关键字上,因为它没有在JPQL中使用。尝试用以下内容替换您的查询:

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

答案 1 :(得分:0)

谢谢!以下是它的结果:

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