Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Assumed i have the following HQL

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

seems not to work. Does anybody have an idea how to solve this problem remain using only one parameter?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
460 views
Welcome To Ask or Share your Answers For Others

1 Answer

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);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...