Reputation: 1951
I am trying to build an API which can search by HQL regex keywords,
EDITED: The best way to perform regex search in HQL is to use criteria, Restrictions.like() or Restrictions.ilike().
public static List<Object> createQueryAnd(Criteria cri,
ArrayList<Parameters> list) {
for (Parameters p : list) {
String value = (String) p.value;
if (value.contains("*")) {
value = value.replace("*", "%");
} else {
value += "%";
}
Criterion c1 = Restrictions.ilike(p.property, value);
cri.add(c1);
}
return cri.list();
}
Hope this helps someone
Upvotes: 3
Views: 15305
Reputation: 42084
HQL does not have regular expressions. If you want to use database provider specific constructs for regular expression, Dialect should be modified. This question contains discussion about how to do that with Oracle database.
Upvotes: 5