Hibernate HQL:将对值作为IN子句中的参数传递

编程入门 行业动态 更新时间:2024-10-16 02:23:10
本文介绍了Hibernate HQL:将对值作为IN子句中的参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了一个问题:如何使用IN子句将参数传递给HQL以获取查询中的对值,例如- select id, name from ABC where (id, reg_date) in ('x', 'y').并且参数具有不同的数据类型,字符串(id)和reg_date(日期). 现在,在HQL中,我可以写:

I am facing a problem: how to pass parameters to HQL for pair values in query with IN clause like - select id, name from ABC where (id, reg_date) in ('x', 'y'). And the parameters are of different data types string (id) and reg_date (date). Now, in HQL I can write:

hql = "select id, Name from ABC where (id, date) in (:listparam1)" hibernateTemplate.findbynamedparam(hql, "listparam1", values).

问题:如何在HQL中传递ID和日期对的列表?这两个参数具有不同的数据类型:一个是String,另一个是Timestamp.我尝试了Map和Object二维数组中两个值的串联,但是没有任何作用.

Problem: how to pass a list of id and date pairs in HQL? Both parameters are of different data types: one is String and the other is Timestamp. I tried Map and concatenation of both values in Object, 2 dimensional array, but nothing is working.

推荐答案

select a.id, a.name from ABC a where a.id || '.' || a.date in (:id_date)

....,您需要将串联的ID和名称的字符串作为参数"id_date"的集合传递.如果性能受到阻碍,则可以在执行完全相同工作的SQL数据库上创建函数索引(当然,如果您的数据库支持函数索引)

....and you need to pass as parameter "id_date" collection of string of concatenated id and name. If performance is an obstacle, you can create function index on your SQL database(s) that do exactly the same job (of course if your database(s) supports function indexes)

更多推荐

Hibernate HQL:将对值作为IN子句中的参数传递

本文发布于:2023-10-27 10:24:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533093.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将对   句中   参数   Hibernate   HQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!