Problemas com HQL INNER JOIN FETCH

1 resposta
awilaz

Estou realizando a seguinte consulta com HQL

StringBuffer hql = new StringBuffer();

hql.append("SELECT tit, max(pcl.dataVencimento) FROM Titulo tit ");

hql.append("INNER JOIN FETCH tit.fornecedor AS frn ");

hql.append("INNER JOIN FETCH frn.dadosPessoais AS pes ");

hql.append("INNER JOIN FETCH pes.enderecosPessoa AS ende ");

hql.append("INNER JOIN FETCH tit.parcelasTitulo AS pcl ");

hql.append("INNER JOIN FETCH ende.cidade AS cid ");

hql.append("INNER JOIN FETCH cid.estado AS est ");

hql.append("WHERE tit.dataRecebimento - tit.dataEmissao > 0 ");

hql.append(“AND tit.dataRecebimento BETWEEN :dataInicial AND :dataFinal”);

if(fornecedor !=null && fornecedor.getCodigo()!=null)

hql.append("AND frn.codigo = "+ fornecedor.getCodigo());

if(numeroTitulo !=null)

hql.append("AND tit.numero = "+ numeroTitulo);

hql.append("AND ende.tipoEndereco = :tipoEndereco ");

hql.append("AND pcl.dataPagamento is null ");

hql.append(“GROUP BY tit”);

Quando rodo a aplicação o seguinte erro aparece. Acredito que seja porque pes.enderecosPessoa AS ende seja uma coleção.
Alguém pode me ajudar??

09:35:41,015 ERROR [PARSER] line 1:438: unexpected token: ende

09:35:41,031 ERROR [STDERR] org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ende near

line 1, column 438 [SELECT tit, max(pcl.dataVencimento) FROM pxt.financeiro.contaspagar.domain.Titul

o tit INNER JOIN FETCH tit.fornecedor AS frn INNER JOIN FETCH frn.dadosPessoais AS pes INNER JOIN FE

TCH pes.enderecosPessoa AS ende INNER JOIN FETCH tit.parcelasTitulo AS pcl INNER JOIN FETCH ende.cid

ade AS cid INNER JOIN FETCH cid.estado AS est WHERE tit.dataRecebimento - tit.dataEmissao > 0 AND ti

t.dataRecebimento BETWEEN :dataInicial AND :dataFinalAND ende.tipoEndereco = :tipoEndereco AND pcl.d

ataPagamento is null GROUP BY tit]

at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)

at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)

at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)

at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:253)

at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:156)

at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:110)

at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:77)

at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:56)

at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)

at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)

at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)

at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1612)

at org.jboss.ejb3.entity.TransactionScopedHibernateSession.createQuery(TransactionScopedHibe

rnateSession.java:378)

1 Resposta

louds

Não, tem um AND sem espaço antes. Coloque tuas queries num arquivo de mapeamento, esse problema não estaria acontecendo, por exemplo.

Criado 26 de outubro de 2006
Ultima resposta 26 de out. de 2006
Respostas 1
Participantes 2