我在 HQL 语句中绑定命名参数,但它只是没有被填充。
//colname = "AdminsInfo.name"; assume it is from method's input
//colval = input.getName().toString(); // assume it is from method's input
String query = "from AdminsInfo where :coln = :colv";
Query q = session.createQuery(query);
q.setParameter("coln",colname);
q.setParameter("colv",colval);
System.out.println(q.toString());
它输出类似这样的内容,这意味着未设置参数(coln,colv)并返回 0 条记录。
QueryImpl(from AdminsInfo where :coln = :colv)
Hibernate: select adminsinfo0_.Row as Row1_0_, adminsinfo0_.ID as ID2_0_,adminsinfo0_.Name as Name3_0_, ... where ?=?
任何有关如何在 HQL 语句中绑定列名的帮助表示赞赏。谢谢。马赫迪。