-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Native SQL Query & regexp & Named Parameter
PostPosted: Wed Sep 26, 2012 1:38 pm 
Newbie

Joined: Wed Sep 26, 2012 10:37 am
Posts: 2
Hi,

Does anyone know if it's possible to extract REGEXP values using named Parameters in Hibernate Native SQL Query?

I have a SQLQuery created using the sessionFactory - the query below runs good when the parameters are embedded into the sql as below:
.... sql ...
sql += "(r.title REGEXP '[[:<:]]" + crit.getKeyword() + "[[:>:]]' ) or (r.annotation REGEXP '[[:<:]]" + crit.getKeyword() + "[[:>:]]') or (r.author REGEXP '[[:<:]]" + crit.getKeyword() + "[[:>:]]'))";

//I changed the above sql to use named parameters (:reg)
sql += "(r.title REGEXP :reg) or (r.annotation REGEXP :reg) or (r.author REGEXP :reg))";
...
SQLQuery sqlQuery = sessionFactory.getCurrentSession().createSQLQuery(sql);
....

String s1 += "'[[:<:]]" + crit.getKeyword() + "[[:>:]]'";
//set the string for the named parameter:
sqlQuery.setString("reg", s1); //am unable to extract the values for the REGEXP out to be used as named Parameters

Would appreciate if anyone has any insight. Thanks in advance! :-)

Lin


Top
 Profile  
 
 Post subject: Re: Hibernate Native SQL Query & regexp & Named Parameter
PostPosted: Fri Sep 28, 2012 10:42 am 
Newbie

Joined: Wed Sep 26, 2012 10:37 am
Posts: 2
Andre,

My apology ... I probably wrote too much in my earlier post and you might have missed the part where I mentioned that I was able to run the query successfully (created with Hibernate sessionFactory) with the embedded parameters.

What I need is to be able to pass in the parameters as named parameters using REGEXP so as to prevent SQL injection. Below was what I did and it was not working:

//I changed the above sql to use named parameters (:reg)
sql += "(r.title REGEXP :reg) or (r.annotation REGEXP :reg) or (r.author REGEXP :reg))";


Thanks.

Lin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.