使用IN子句Hibernate createNativeQuery [英] Hibernate createNativeQuery using IN clause

查看:1194
本文介绍了使用IN子句Hibernate createNativeQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Java,Hibernate。

我有一个查询

  String pixIds =1,2,3; 
String query =SELECT * FROM comment WHERE PIX_ID IN(:pixIds);
q.setParameter(pixIds,pixIds);
List< Object []> results = q.getResultList();

我无法使用上面的代码将此参数绑定到pixIds。注意:我在这里的查询是我实际查询的简化版本。

public Query setParameterList(String name,Collection vals)throws HibernateException


Using Java, Hibernate.

I have a query

String pixIds = "1,2,3";
String query = "SELECT * FROM comment WHERE PIX_ID IN (:pixIds)";
q.setParameter("pixIds", pixIds);
List<Object[]> results =  q.getResultList();

I'm not able to bind this parameter to pixIds using the code above. What is the right way to do this?

Note : the query I have here is a simplified version of my actual query.

解决方案

The following method works
public Query setParameterList(String name, Collection vals) throws HibernateException

这篇关于使用IN子句Hibernate createNativeQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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