Hibernate HQL:将对值作为IN子句中的参数传递 [英] Hibernate HQL: pass pair values as parameters in IN clause

查看:474
本文介绍了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.我尝试了MapObject二维数组中两个值的串联,但是没有任何作用.

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子句中的参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆