Given the following table, where wildcard
is a String:
ID wildcard
1 foo
2 fo
3 f
I'd like to be able to build a Hibernate Criterion
for matching against an input field that matches any of the wildcard
's fields.
The following example should clarify what I mean by "match":
querying with "foobar" should match all 3 of these rows since:
foo%
, fo%
, and f%
all include foobar
In other words, I'd like the query to return where the input value begins with a row's wildcard
column.
One way for me to do this would to be set an or
criterion term where I check if the wildcard
equals each of the pieces of foobar
.
Example:
select * from table where wildcard = 'f' or wildcard = 'fo' or
wildcard = 'foo' or wildcard = 'foob' or
wildcard = 'fooba' or wildcard = 'foobar'
But I'm sure that I could do better?
How can I do this with a Hibernate Criterion
?