Hibernate regex query

I want to achieve the effect of the following query in Hibernate, but I cannot find a way to do this.

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

Can anyone help?

+6
source share
1 answer

Hibernate QL does not support regular expressions (and some engines have very low support for regular expressions). You can convert your request to

 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 support for regular expressions you will have to write your own SQL (if your database supports regular expressions at all)

+6
source

Source: https://habr.com/ru/post/886956/


All Articles