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
|