Hibernate 命名查询参数

发布于 2024-08-06 12:42:50 字数 360 浏览 2 评论 0原文

我在命名查询参数方面遇到问题。我的查询如下:

<sql-query name="getCustomer">
<![CDATA[
     select * from customer where customerId=:custId and billId in ( :billIdList )
]]>
</sql-query>

我正在设置所有参数,但在 :billIdList 中遇到问题,每当我设置此参数时,我都会得到一个空的客户列表。我的 :billIdList 是字符串形式,例如:5,6,7,9。 DB中有数据也具有上述值。当我编写查询时它工作正常 在自己的程序中。

请帮我。

I am having problem with named query parameter. My query is as follow:

<sql-query name="getCustomer">
<![CDATA[
     select * from customer where customerId=:custId and billId in ( :billIdList )
]]>
</sql-query>

I am setting all parameters, but having problem in :billIdList whenever I am setting this parameter I am getting a Empty list of customers. My :billIdList is in the string form e.g: 5,6,7,9. There is data in DB also with above values. It works fine when I am writing query
in program it self.

Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖心男生 2024-08-13 12:42:50

对于具有多个值的参数,您需要使用 Hibernate 的 Query 接口的 setParameterList() 方法:

query.setParameterList("billIdList", new int[] {5,6,7,9});

For parameters with more than one value you need to use a setParameterList() method of Hibernate's Query interface:

query.setParameterList("billIdList", new int[] {5,6,7,9});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文