I have attempted to use an HQL query with named parameters. The query is quite complicated, something like this
Code:
select
v.VariableId as VariableId,
vv.VariableValueId as VariableValueId,
case
when vv.VariableValueId is not null then
case
when vst.ValueSourceTypeId = :autoLoad then vv.Value
else null
end
else null
end as Formula
case
when vv.VariableValueId is not null then
case
when vv.Value is null then v.SimulationValue
when vst.ValueSourceTypeId = :autoLoad then null
else vv.Value
end
when v.IsFormulaBased = 0 then v.SimulationValue
else null
end as Value,
case
when (vv.VariableValueId is not null and vst.ValueSourceTypeId = :autoLoad) or (vv.VariableValueId is null and v.IsFormulaBased = 1) then
:value1
else
:value2
end as EvaluationStatus
from Variable v
left join v.Formula f
left join v.VariableValues vv with vv.Organization.OrganizationId = :organizationId and vv.TimePeriod.TimePeriodId = :timePeriodId
left join vv.ValueSourceType vst
left join vv.CurrentOverride ov
where v.Frequency.FrequencyId = (select tp.Frequency.FrequencyId from TimePeriod tp where tp.TimePeriodId = :timePeriodId)
I set the parameters using SetParameter calls.
When the query gets translated to sql and executed, the parameters are completely f****d up. I attempted to debug and I noticed that the query gets translated to a form that uses the jdbc syntax with question marks as parameter placeholders but I didn't have time to dig deeper and see exactly where things get screwed up.
Please note that some parameters are used multiple times. Is that allowed? I even tried to have unique parameters names but, still, the parameter values were not assigned correctly.
Did anyone come across this problem? To me this is a major bug and I am very surprised by this behavior. Unless I am missing something obvious - maybe a setting somewhere.
Please note that the hql query is built in c# code and I ended up using the good old String.Format. I didn't attempt to use named queries.
Thanks
PS. I am using version 3.1.0.