標籤:hibernate 預留位置 具名引數 in
早期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<list.size(); i++) {
Org org = (Org)list.get(i);
System.out.println(i + "---" + org.getId());
}
System.out.println("-----------------testMixParameterMethod ok------------------------");
}
本文出自 “robinc” 部落格,請務必保留此出處http://robinc.blog.51cto.com/439699/1565211
關於hibernate混合使用預留位置和具名引數