6

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?

1 Answer 1

6

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)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but value in my column will be like this 'fripro' ( are just delimiters). How do I work out this?
select e.TITLE from EVENTS e where e.TITLE like 'fri%pro' OR e.TITLE like '%fri%' OR e.TITLE like '%pro%' Pick what "like" you like more :-) i.e. which one meets your conditions since they are still unclear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.