Hibernate HQL语句的参数配置
以hql举列:更多的查辅佐
// 利用List为参数作为条件功效
List<Integer> lst = new ArrayList<Integer>();
lst.add(14);
lst.add(15);
lst.add(17);
String hql = "from Students s where s.SId in (:lst)";
Query q = session.createQuery(hql);
q.setParameterList("lst",lst);
// 以一个实类作为参数条件
hql = "from Students s where s.class=:class";
q.setEntity("class",session.get(Class.class,1));
// 按照给的参数匹配对应的范例Type hiberntae里的类
hql = "from Students s where s.SId=? or s.SName=?";
Query q = session.createQuery(hql);
q.setParameters(new Object [] { 14,"update" },new Type [] { new IntegerType(),new StringType() });