Early hibernate does not support the use of JDBC-style placeholders and named parameters in a mixture of two ways
But the new version of Hibernate can be supported,
@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, "Haidian"); Placeholder Mode
Queryobject.setparameter (1, 102);
Queryobject.setparameter ("Address", "Haidian");
queryobject.setparameterlist ("Codes", New integer[]{102, 103, 104}); Named parameter mode
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------------------------");
}
This article is from the "Robinc" blog, make sure to keep this source http://robinc.blog.51cto.com/439699/1565211
About hibernate blending using placeholders and named parameters