-->
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.  [ 1 post ] 
Author Message
 Post subject: 'Contains' operator in HQL
PostPosted: Fri Jul 08, 2005 10:13 am 
Newbie

Joined: Wed Jun 15, 2005 9:18 am
Posts: 11
Hello guys,

I am looking for an elegant manner to query a field in HQL with the equivalent of the CatSearch operator in Oracle.
With this operator you can retrieve every line where a colum (let's say a column named 'content') contains words "Hibernate" and "Oracle"
Example : select [...] from [...] where CatSearch (Content, 'Hibernate | Oracle', Null ) > 0
returns every line whose 'content' column contains "Hibernate" and "Oracle", even if these two words are not side to side.
It is very usefull, you can use the same statement whatever the number of words composing the input string.

What I want to avoid in HQL :

StringBuffer query = new StringBuffer("from "+myClass.class.getName()+" x where 0=0 ");
String[] keywords = input.split(" ");
for (int i = 0; i < keywords.length; i++)
{
query.append("and x.content like :keyword").append(i).append(" ");
}
Even if it works it remains a workaround,

Is there an operator (let's call it 'contains') which would make possible a such query :
String query = "from "+myClass.class.getName()+" x where x.content contains :input";
and the :input parameter is set to input.split(" ") or input.split(",")...

Translated in SQL, the query would become
Select [...] From [...] Where content Like '%Hibernate%' and content Like '%Oracle%'

Thanks for your opinion on this point, I did not find anything about this in the doc

Gengis


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

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.