Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex query in Hibernate

I want to achieve the effect of following query in Hibernate, but I'm unable to figure out a way to do this.

select e.TITLE from EVENTS e where e.TITLE REGEXP 'fri|pro';

Can someone help?

like image 253
Shwetanka Avatar asked Apr 29 '11 12:04

Shwetanka


1 Answers

Hibernate QL doesn't support regular expressions (and some engines have a very poor regexes support). You can transform your query to be

select e.TITLE from EVENTS e where (e.TITLE = 'fri' OR e.TITLE = 'pro');

or

select e.TITLE from EVENTS e where e.TITLE in ('fri','pro');

But for real regex support you'll have to write custom SQL (if your DB does support regexes at all)

like image 57
Augusto Avatar answered Oct 04 '22 20:10

Augusto