[英]HQL query to find the data using in clause
I am trying to access the certain data using in clause but the following exception 我正在尝试使用in子句访问某些数据,但以下异常
unexpected token: Customer near line 1, column 81 [from app.com.db.DTO.SmsSourceDTO as sms where sms.description in ( Registered Customer,External DB,Birthday)]
意外令牌:第1行第81列附近的客户[来自app.com.db.DTO.SmsSourceDTO,为sms,其中sms.description位于(注册客户,外部DB,生日)]
displayed 显示
SmsSourceDTO.java SmsSourceDTO.java
@Table(name = "sms_source_tbl")
public class SmsSourceDTO implements Serializable {
private Integer id;
private String description;
}
. 。
TestHql.java TestHql.java
listOfSelectedDatabase = {Registered Customer,External DB,Birthday};
String hqlString = "from SmsSourceDTO as sms where sms.description in(" + listOfSelectedDatabase +")";
getResultSetByHQL(hqlString));
protected List getResultSetByHQL(String hql) throws DataBaseException {
Query query = null;
query = getHbSession().createQuery(hql);
session = null;
return query.list();
}
while debugging I got the following query => from SmsSourceDTO as sms where sms.description in ( Registered Customer,External DB,Birthday)
调试时,我
from SmsSourceDTO as sms where sms.description in ( Registered Customer,External DB,Birthday)
收到以下查询=> from SmsSourceDTO as sms where sms.description in ( Registered Customer,External DB,Birthday)
Can anybody help. 谁能帮忙。
You are trying to add a parameter list to an HQL query. 您正在尝试将参数列表添加到HQL查询。 I recommend you to use hibernate parameter binding to do this.
我建议您使用休眠参数绑定来执行此操作。
So first, if you want to include a list of string values, creates it before using 因此,首先,如果要包括字符串值列表,请在使用前创建它
List<String> listOfSelectedDatabase = Arrays.asList("Registered Customer", "External DB", "Birthday");
instead 代替
listOfSelectedDatabase = {Registered Customer,External DB,Birthday};
Then creates a param in HQL query and provide its value as follows: 然后在HQL查询中创建一个参数,并提供其值,如下所示:
String hqlString = "from SmsSourceDTO as sms where sms.description in (:paramList)";
Query query = session.createQuery(hqlString);
query.setParameterList("paramList", listOfSelectedDatabase);
Finally, what is this session = null;
最后,此
session = null;
是什么session = null;
for? 对于? I don't get the point of that sentence.
我不明白那句话的意思。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.