![](/img/trans.png)
[英]Hibernate full text search using hibernate-search-4.1.1.Final.jar but having error like query builder can not resolved
[英]Search query using like with AND logic in hibernate
我們在應用程序中使用的是休眠3.6.3最終版和MySql數據庫。 我需要使用Java將以下Mysql查詢轉換為HQL。
select * from user where name like "%mohan%" and name like '%ram%';
如何在休眠和Java中執行此邏輯AND運算符?
編輯:
您需要動態定義hql查詢:
String[] likes = {"foo", "bar"};
String myQuery = "select e from User e where 1=1";
for(int i=0; i<likes.length; i++){
myQuery+= " and e.name like :"+i;
}
Query query = getSessionFactory().getCurrentSession().createQuery(myQuery);
for(int i=0; i<likes.length; i++){
query.setParameter(i, "%"+likes[i]+"%");
}
query.list();
注意:您可以使用StringBuilder連接字符串
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.