如何在HQL中编写类似的查询 [英] How to write a like query in HQL

查看:84
本文介绍了如何在HQL中编写类似的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行搜索特定字符串的特定字符串。
例如,如果起始字母表是'A' den,它应该产生一个结果,其中将包含所有字母表' A'

I want to perform search for a particular string that is starting with a particular alphabet. So, for example if the starting alphabet is 'A' den it should produce a result which will contain all the strings with alphabet 'A'.

我如何做到这一点?

我的查询是如下所示

My query is as shown below

Query qry = session.createQuery("From RegistrationBean as rb where rb."+searchCriteria+"  like %?%");
qry.setString(0,searchField);


推荐答案

将您的查询改为:

Query qry = session.createQuery("From RegistrationBean as rb where rb."+searchCriteria+"  like ?");
qry.setString(0, "%"+searchField+"%");

这篇关于如何在HQL中编写类似的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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