Hibernate(HQL) - 如何查询“where Many in()”多对多
我有一个拥有许多汽车的用户实体。
我无法使用“IN”语句获取用户的汽车列表。
List<Car> cars = getCarsList();
String hql = "From User WHERE user.cars in(:cars)";
Query query = session.createQuery(hql)
query.setParameterList("cars",cars);
//query.setParameterList("cars",cars.toArray());//not working also
//query.setParameter("cars","1,4,8,30");//not working also
query.setMaxResults(1);
这样,参数是 cars 就被忽略了。
我也尝试发送 vars.toArray();
我还尝试发送字符串 1,4,8,300(如果是汽车,则为 ID)。
I have a user entity that has many cars.
I cant fetch the user by car list with "IN" statement.
List<Car> cars = getCarsList();
String hql = "From User WHERE user.cars in(:cars)";
Query query = session.createQuery(hql)
query.setParameterList("cars",cars);
//query.setParameterList("cars",cars.toArray());//not working also
//query.setParameter("cars","1,4,8,30");//not working also
query.setMaxResults(1);
In this way, the parameter is cars being ignored.
I have also tries to send vars.toArray();
And I also tried to send String 1,4,8,300 (Ids if cars).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
未定义用户别名。尝试使用
carIds 是包含汽车 ID 的集合(而不是第三次尝试中的字符串)。
The user alias is not defined. Try with
where carIds is a collection (and not a string as in your third try) containing the IDs of the cars.