早期hibernate不支持jdbc风格的占位符和命名参数两种方式混合使用
但是新版本的hibernate是可以支持的,
@Test
public void testMixParameterMethod() {
//String hqlString ="from Org org where org.address = ? and org.code = ? ";
//String hqlString ="from Org org where org.address = :address and org.code in (:codes) ";
String hqlString ="from Org org where org.address = ? and org.code in (:codes) ";
Query queryObject = getSession().createQuery(hqlString);
queryObject.setParameter(0, "海淀"); //占位符方式
//queryObject.setParameter(1, 102);
//queryObject.setParameter("address", "海淀");
queryObject.setParameterList("codes", new Integer[]{102, 103, 104}); //命名参数方式
List> list = queryObject.list();
for (int i=0; i
Org org = (Org)list.get(i);
System.out.println(i + "---" + org.getId());
}
System.out.println("-----------------testMixParameterMethod ok------------------------");
}
原文:http://robinc.blog.51cto.com/439699/1565211