Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wild card Search in hibernate

 
aadhar sharma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i perform wild card search using hibernate criteria api
 
Hung Tang
Ranch Hand
Posts: 148
 
Halcon Guatemala
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi aadhar, could You specify more precisely? What kind of wild card search do you refer?
 
aadhar sharma
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Hung
 
Halcon Guatemala
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank again Dude
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic