java - createSQLQuery with parameter in Hibernate -


i'm trying run this:

.. string modeltablename = (model == tablemodeltype.ring) ? "ring_players" : "tourny_players";  list<object[]> results = dbs.createsqlquery("select group_level, count(group_level) :modeltablename game_id=:gameid group group_level")                 .addscalar("group_level", hibernate.integer)                 .addscalar("count(group_level)", hibernate.long)                 .setstring("modeltablename", getmodeltablename())                 .setinteger("gameid", getgameid())                 .list(); 

it gives exception:

caused by: java.sql.sqlexception: ora-00903: invalid table name 

if write "ring_players" instead of ":tablemodelname" works!

what doing wrong parameter?

thank you.

according answer, can not inject table name: table name parameter in hql

you may have construct as:

list<object[]> results = dbs.createsqlquery("select group_level, count(group_level) " + getmodeltablename() + " game_id=:gameid group group_level")                 .addscalar("group_level", hibernate.integer)                 .addscalar("count(group_level)", hibernate.long)                 .setinteger("gameid", getgameid())                 .list(); 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -