Using hibernate named parameter twice

后端 未结 2 1976
再見小時候
再見小時候 2020-12-18 18:55

Assumed i have the following HQL

EntityManager.createQuery(\"SELECT a FROM a WHERE a.b = :par OR a.c = :par\").setParameter(\"par\", obj);

相关标签:
2条回答
  • 2020-12-18 19:19
    setParameter(String name,Object val)
    

    Replaces all occurence of name, specified in the query.

    0 讨论(0)
  • 2020-12-18 19:27
    setParameter(String name,Object val)
    

    This is used to bind a value to the named parameter. But a name can occur multiple times in a query that doesn't matter. So check once whether you have really data for that query.

    check the documentation here

    Some main text from that documentation

    Named query parameters are tokens of the form :name in the query string. A value is bound to the integer parameter :foo by calling setParameter("foo", foo, Hibernate.INTEGER); for example. A name may appear multiple times in the query string.

    If still u don't get the result then just try with using two names and set it

    EntityManager.createQuery("SELECT a FROM a WHERE a.b = :par1 OR a.c = :par2").setParameter("par1", obj).setParameter("par2", obj);

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