我遇到了一个问题:如何使用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子句中的参数传递
发布评论