Java 如何在hql/hibernate中的一组值中使用equals?
我想使用如下查询:Java 如何在hql/hibernate中的一组值中使用equals?,java,hibernate,orm,hql,Java,Hibernate,Orm,Hql,我想使用如下查询: from myModel t where t.f inEqual(1,2,3,4,5) 与此相反: from myModel t where t.f = 1 and t.f = 2 and t.f = 3 and t.f = 4 and t.f = 5 from myModel t where t.f > 1 and t.f > 2 and t
from myModel t
where t.f inEqual(1,2,3,4,5)
与此相反:
from myModel t
where t.f = 1
and t.f = 2
and t.f = 3
and t.f = 4
and t.f = 5
from myModel t
where t.f > 1
and t.f > 2
and t.f > 3
and t.f > 4
and t.f > 5
或者可能是这样:
from myModel t
where t.f inGreaterThan(1,2,3,4,5)
与此相反:
from myModel t
where t.f = 1
and t.f = 2
and t.f = 3
and t.f = 4
and t.f = 5
from myModel t
where t.f > 1
and t.f > 2
and t.f > 3
and t.f > 4
and t.f > 5
实际上,
inEqual
和InCreateThan
在hql中不是一个函数,但我想使用一个功能,您只能对多个“或”这样做:
List<String> valueList = new ArrayList<>();
valueList.add("1");valueList.add("2");valueList.add("3");
Query query2 = session.createQuery("from myModel t where t.f in (:values)").setParameterList("values", valueList);
query2.list();
List valueList=new ArrayList();
价值清单。添加(“1”);价值清单。添加(“2”);价值清单。添加(“3”);
Query query2=session.createQuery(“来自myModel t,其中t.f位于(:values)”).setParameterList(“values”,valueList);
query2.list();
对于多个and和大于etc,hibernate标准不提供任何API。如果你想要这样的操作,你可以选择
查询DSL为此提供了
inAll()
和goeAll()
等功能。您可以在SQL中使用其中的t.f('1','2')
从id位于('1','2')的用户中选择*
不,这不是一个解决方案,因为子句中的
与此子句类似,其中t.f=1或t.f=2或t.f=3
@RasoolGhafari我已更新了我的答案。hibernate没有为它提供任何API。你应该重写你的例子:where t.f>1和。。。而t.f>5
可以写成,其中t.f>5
——据我猜测,这不是你想问的问题。