我正在使用hibernate对此查询进行编码。但它没有用。似乎别名c是未知的。 有人知道这是什么问题吗?
static final String BEGIN_QUERY = "SELECT c.contratoId, c.contrato, c.classificacao, c.responsavel, c.uf, c.sigla,"
+ "c.statusContrato, c.fornecedor, c.site, c.login, c.senha, c.telefone, c.cnpj, c.codigoFornecedor, c.hidrometro"
+ "c.nome, c.endereco, c.despesa, c.descricao, c.mp, c.status, c.estadoLancamento"
+ "h.historicoId, h.dataCobranca, h.dataVencimento, h.dataEmissao, h.dataLancamento, h.dataCompensacao, h.dataAtualizacao, h.docPgt, h.docCompensacao"
+ "FROM Contrato c, Historico h"
+ "WHERE c.contratoId = h.contratoId"
+ "AND 1=1";
EXCEPTION:
Caused by: org.hsqldb.HsqlException: unexpected token: C
at org.hsqldb.error.Error.parseError(Unknown Source)
at org.hsqldb.ParserBase.unexpectedToken(Unknown Source)
at org.hsqldb.ParserDQL.XreadSelect(Unknown Source)
at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
at org.hsqldb.Session.compileStatement(Unknown Source)
at org.hsqldb.StatementManager.compile(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 19 more
答案 0 :(得分:1)
你错过了几个空格和逗号
static final String BEGIN_QUERY = "SELECT c.contratoId, c.contrato, c.classificacao, c.responsavel, c.uf, c.sigla, "
+ "c.statusContrato, c.fornecedor, c.site, c.login, c.senha, c.telefone, c.cnpj, c.codigoFornecedor, c.hidrometro, " // here
+ "c.nome, c.endereco, c.despesa, c.descricao, c.mp, c.status, c.estadoLancamento, " // here
+ "h.historicoId, h.dataCobranca, h.dataVencimento, h.dataEmissao, h.dataLancamento, h.dataCompensacao, h.dataAtualizacao, h.docPgt, h.docCompensacao " // here
+ "FROM Contrato c, Historico h " // here
+ "WHERE c.contratoId = h.contratoId " // and here
+ "AND 1=1";