-->
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.  [ 3 posts ] 
Author Message
 Post subject: Where clause in Query with " ... contains "*""?
PostPosted: Sun Oct 04, 2009 6:23 pm 
Newbie

Joined: Sun Oct 04, 2009 6:15 pm
Posts: 1
Hi,

I just read the documentation about the where-clause and the expressions, but i did not find a sufficient answer.

I want to do the following:
A query via hibernate. I do have currently the following query:
".createQuery("from XXXObject as ac where ac.text like :text").setParameter("text", text);"
(text is not the primary key of the table, so there might be some results)
This one is working fine, but now I need a query which is not looking for the whole text. BUT: the query should return all values which contain for example a "*" or a "?".

Sorry if it is an easy answer and I was just too dumb to find it.

Thanks in advance & Regards,
Lukas


Top
 Profile  
 
 Post subject: Re: Where clause in Query with " ... contains "*""?
PostPosted: Sun Oct 04, 2009 9:49 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
You can use:
Code:
Query q = session.createQuery("from XXXObject as ac where ac.text like :text");
q.setString("text", "%value%");
q.list();


Top
 Profile  
 
 Post subject: Re: Where clause in Query with " ... contains "*""?
PostPosted: Mon Oct 05, 2009 5:47 pm 
Newbie

Joined: Fri Sep 11, 2009 11:35 am
Posts: 3
If your looking to return an object if ac.text contains either a "*" or a "?" you could go with:

Code:
Query q = session.createQuery("from XXXObject as ac where ac.text like :text or ac.text like :text2");
q.setString("text", "%*%");
q.setString("text2", "%?%");
q.list();


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