This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Wild card Search in hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Wild card Search in hibernate" Watch "Wild card Search in hibernate" New topic
Author

Wild card Search in hibernate

aadhar sharma
Ranch Hand

Joined: Oct 09, 2006
Posts: 38
how can i perform wild card search using hibernate criteria api


Thanks and Regards
Hung Tang
Ranch Hand

Joined: Feb 14, 2002
Posts: 148
Your answer is found: http://www.hibernate.org/hib_docs/v3/reference/en/html/querycriteria.html
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi aadhar, could You specify more precisely? What kind of wild card search do you refer?


"La verdadera sabidur´┐Ża viene del temor de Dios"
aadhar sharma
Ranch Hand

Joined: Oct 09, 2006
Posts: 38
Hi Halcon,


I need to search the following patterns

Case 1:
let me take an example ABC_DEF

now the system should return all the values in the underscore _

- specifies only one space only one blank character can be filled there

for eg ABCaDEF
ABCbDEF
ABCcDEF

also

Case 2:

input %a%

output

bab
bbbabbb
bbbaaaa

Case 3:

%a

all the strings containing a
aadhar sharma
Ranch Hand

Joined: Oct 09, 2006
Posts: 38
Thanks Hung
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi again aadhar, thanks for explaining.

I believe both, cases 2 and 3 are possible because Restrictions.like is traduced as SQL like and it supports '%' wildcards to discover string patterns.

Respect to case 1, I don't know about how it can be done with Criteria API, I have worked in HQL combination with SUBSTR because my database supports it, like something:

aadhar sharma
Ranch Hand

Joined: Oct 09, 2006
Posts: 38
Thank again Dude
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Wild card Search in hibernate