-->
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: Contains clause using Criteria
PostPosted: Fri Mar 20, 2009 2:32 pm 
Newbie

Joined: Fri Mar 20, 2009 2:04 pm
Posts: 1
Hi,

I am new to hibernate and here is my problem:

I want to return companies which has both words "ABC" and "INVESTMENT" in their names.

I am using criteria API and trying to play with
crt.add(Restrictions.like("name", "ABC"));
crt.add(Restrictions.like("name","INVESTMENT");

The problem with above code is, the query is returning below results

1) ABC INVESTMENT CORPORATION
2) ABC INVESTMENTS COMPANY
3) ABCD INVESTMENT CORPORATION
4) ABCD INVESTMENTS CORPORATION

As per my requirement, I should return the names which contains the exact words. In the above results, system is supposed to send item#1 (not 2, 3, 4) only.

Any help is highly appreciated.

Thanks,
Gupta


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 20, 2009 3:50 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
I don't know if Hibernate Offers anything like search words as opposed to series of charaters..
Try with a leading space and trailing space.
so your query will be something like:-

crt.add(Restrictions.like("name", " ABC "));
crt.add(Restrictions.like("name"," INVESTMENT ");

so that its a search on the word and not on the character sequence match.

Hope this helps,
Latha.


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.