针对 PostgreSQL 数据库的 HQL 查询:
var checkLines = _Session.CreateQuery(
@"select lines from FinancialStatement statement
inner join fetch statement.FinancialStatementLines lines
where statement.FinancialStatementId = :statementId
and lines.TransactionType = :transactionType
and length(lines.CheckNumber) > 0")
.SetParameter("statementId", statement.FinancialStatementId)
.SetParameter("transactionType", TransactionTypes.Debit)
.List<FinancialStatementLine>();
该查询对我来说看起来不错,但我是 HQL 的新手。有人可以告诉我我做错了什么吗?我假设问题出在 HQL 上,如果您认为我需要寻找其他地方,请告诉我。
情节变稠了
在检查上述 HQL 创建的查询后,我发现它看起来像这样:
select
financials1_.LineId as LineId14_,
financials1_.FinancialStatementId as Financia2_14_,
financials1_.APPaymentID as APPaymen3_14_,
financials1_.EffectiveDate as Effectiv4_14_,
financials1_.Amount as Amount14_,
financials1_.TransactionType as Transact6_14_,
financials1_.CheckNumber as CheckNum7_14_,
financials1_.Description as Descript8_14_,
financials1_.VendorDescription as VendorDe9_14_,
financials1_.FinancialStatementId as Financia2_,
financials1_.LineId as LineId
from
FinancialStatements financials0_
where
financials0_.FinancialStatementId=:p0
and financials1_.TransactionType=:p1
and length(financials1_.CheckNumber)>0
...现在,WTF?子句中select
不存在子句别名from
,这解释了错误,但当然不是错误存在的原因。
我该如何解决这个问题?