Hibernate Column name Parameter Binding

后端 未结 2 936
我在风中等你
我在风中等你 2020-12-11 17:50

I am binding Named Parameters in a HQL statement, but it just doesn\'t get filled.

//colname = \"AdminsInfo.name\"; assume it is from method\'s input
//colva         


        
相关标签:
2条回答
  • 2020-12-11 18:29

    Try to replace Query for Criteria.

    Criteria c = session.createCriteria(AdminsInfo.class);
    c.add(Restrictions.eq(colname,colval));
    c.list();
    
    0 讨论(0)
  • 2020-12-11 18:48

    You can't bind a column name as a parameter. Only a column value. This name has to be known when the execution plan is computed, before binding parameter values and executing the query. If you really want to have such a dynamic query, use the Criteria API, or some other way of dynamically creating a query.

    0 讨论(0)
提交回复
热议问题