简体   繁体   English

Hibernate 的 setparameterlist 不适用于 selectquery

[英]Hibernate's setparameterlist not working for the selectquery

i am trying to set the parameter lTList in the sqlquery with something like this => ['a',b','c'] but when i SOP after setting the parameter there is no change => "select.... lt in (:ltList) " what am i doing wrong我试图在 sqlquery 中设置参数 lTList 像这样 => ['a',b','c'] 但是当我设置参数后 SOP 没有变化 => "select.... lt in (:ltList) “我做错了什么


//List lTList=new ArrayList<String>();   
        
 Query selectQr = session.createSQLQuery("select id ipfs from ipfs where lt in(:lTList) and user_id='" + userId + "'");

selectQr.setParameterList("lTList", lTList);

There is no error but: query constructed: select.... lt in (:ltList)没有错误但是:查询构造:select.... lt in (:ltList)

query wanted: select.... lt in ('a','b','c')想要查询:select.... lt in ('a','b','c')

"in(:lTList)" "in" and "()" need a blank space "in(:lTList)" "in" 和 "()" 需要一个空格

id ipfs is one column in ipfs table or two?? id ipfs 是 ipfs 表中的一列还是两列?

if id is a column and ipfs is an other one, you should add comma , id, ipfs如果 id 是一列而 ipfs 是另一列,则应添加 comma , id, ipfs

else you should replace the column with 'id ipfs'否则你应该用'id ipfs'替换列

The second comment was correct,第二个评论是正确的,

=>Why should the query change? =>为什么要改变查询? THe parameters are applied upon execution.参数在执行时应用。 Also you should never use concat to create a query like this.此外,您永远不应该使用 concat 来创建这样的查询。 Use another parameter to set the userid.使用另一个参数来设置用户标识。 - M. Deinum - M. Deinum

The problem was that the setparameterlist was setting the parameters with quotes '', and i was already sending a list with quotes appended, thus on execution it became something like this- (''a'',''b'',''c'')问题是 setparameterlist 正在设置带有引号''的参数,并且我已经发送了一个带有引号的列表,因此在执行时它变成了这样的东西 - (''a'',''b'','' C'')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM