gpt4 book ai didi

java - 如果查询是动态语句,如何在hibernate中绑定(bind)查询参数?

转载 作者:太空宇宙 更新时间:2023-11-04 12:22:08 25 4
gpt4 key购买 nike

我的动态查询为:

DECLARE @LOERangeMin int =0 ;
DECLARE @LOERangeMax int = 0;
DECLARE @CycleStartStatus nvarchar(500) = :param1;
DECLARE @CycleEndStatus nvarchar(500) = :param2;
DECLARE @Team nvarchar(100) = NULL;
DECLARE @ReportStartDate datetime = NULL;
DECLARE @ReportEndDate datetime = GETDATE();

select min([Cycle Time]) AS AvgMinCycleTime,max([Cycle Time]) AS AvgMaxCycleTime,AVG([Cycle Time]) AS AvgCycleTime
from EpicTable where EpicStartStatusName = @CycleStartStatus and EpicEndStatusName = @CycleEndStatus

I am preparing Query object by passing this query as a string as :

Query que = session.createSQLQuery(queryString);

In this I want to set CycleStartStatus and CycleEndStatus using que.setParameter("param1",CycleStartStatus); and que.setParameter("param2",CycleEndStatus);

我尝试了这种方式,但它显示“org.hibernate.QueryParameterException:无法找到命名参数[param1]”。那么有人可以帮我解决我该怎么做吗?

最佳答案

您必须使用以下表示法放置 HQL 参数::paramName。像这样:

select min([Cycle Time]) AS AvgMinCycleTime,
max([Cycle Time]) AS AvgMaxCycleTime,
AVG([Cycle Time]) AS AvgCycleTime
from EpicTable where EpicStartStatusName = :param1
and EpicEndStatusName = :param2

然后:

Query que = session.createSQLQuery(queryString);
que.setParameter("param1",CycleStartStatus);
que.setParameter("param2",CycleEndStatus);

关于java - 如果查询是动态语句,如何在hibernate中绑定(bind)查询参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38760046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com