-->
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.  [ 6 posts ] 
Author Message
 Post subject: Using Like for pattern matching in HQL
PostPosted: Tue Oct 31, 2006 9:20 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26



Hi

I am new to hibernates.

I am using hibernates HQL like statement to get the data from the database. Here is code :

getdetails=session.createQuery("select c from CommandBean as c where c.actionFunction like :var ");
getdetails.setString("var",actionFunction);

Suppose actionFunction pdommara , then it will return list of data.

But when actionFunction is like %pdom%( String str="%"+actionFunction+"%";) , it is not returning any list of values.

Pls any one can help me !!

Thanks In Advance
Praveen.


Top
 Profile  
 
 Post subject: Re: Using Like for pattern matching in HQL
PostPosted: Tue Oct 31, 2006 11:08 am 
Beginner
Beginner

Joined: Sat Sep 09, 2006 5:55 am
Posts: 23
pdommara wrote:
getdetails=session.createQuery("select c from CommandBean as c where c.actionFunction like :var ");
getdetails.setString("var",actionFunction);


Strange, that should work, this is how we do it:
Code:

queryString.Append(fieldName + " LIKE " + ":" + key)
// ...
getdetails.setParameter(key, "%" + fieldValue + "%");


I'm not sure why this would act different from your code, but it seems to work ok overhere.

_________________
Cheers,

Guy Mahieu


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 1:36 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi guymahieu,


It worked !!


Thanks for Reply !!

Thanks A lot !!

But wants to know what is diffrence in between :


str="%"+actionFuncation+"%";

query.setString("key",str);
and
query.setString("key","%"+actionFuncation+"%");

pls reply me !!

Praveen.


Last edited by pdommara on Wed Nov 01, 2006 5:13 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 1:37 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi guymahieu,


It worked !!


Thanks for Reply !!

Thanks A lot !!

But wants to know what is diffrence in between :


str="%"+actionFuncation+"%";

query.setString("key",str);
and
query.setString("key","%"+actionFuncation+"%");

pls reply me !!

Praveen


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 5:27 am 
Beginner
Beginner

Joined: Sat Sep 09, 2006 5:55 am
Posts: 23
pdommara wrote:
But wants to know what is diffrence in between :
str="%"+actionFuncation+"%";
query.setString("key",str);
and
query.setString("key","%"+actionFuncation+"%");


Hehe, nothing! So I guess it went wrong for another reason before. Good thing you have it working now though.

_________________
Cheers,

Guy Mahieu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 12:12 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Ok


Thanks For great Support !!


praveen.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.