3

I am able to fire query in query browser (my sql) and able to retrieve record like below SELECT * FROM details WHERE title REGEXP 'dem';

but when I use similar type of code in server side then I is giving error as unexpected token: REGEXP

After searching on web, it seems that hibernate does not support REGEXP. but some solution are also given which are not relevant to that. I need to handle this through query only in hibernate.

sbQuery.append("select distinct id from deatil id");
sbQuery.append("where ((id.title like :keyword) OR (id.description like :keyword) ");
sKhan
  • 9,694
  • 16
  • 55
  • 53
OPTIMUS
  • 672
  • 4
  • 14
  • 29
  • Related : [Regex query in Hibernate](http://stackoverflow.com/q/5831768/4290096) – Arun Xavier Mar 15 '16 at 08:19
  • Thanks for this, But for me this is not working because i need regex only. Workaround given i have already applied but these do not fulfilling my requirement else creating more issues. Any other way or suggestion – OPTIMUS Mar 15 '16 at 09:00

2 Answers2

0

You could add your own custom function in the Hibernate dialect for your database.

I tried adding a custom function that was a bit more complex than this and I had issues to make it work, hopefully the simpler ones should work out of the box.

Community
  • 1
  • 1
Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110
0
    Query query = session.createSQLQuery("select distinct id from deatil id where (id.title like :keyword) OR (id.description like :keyword)")
.setParameter("keyword", keyword);
List result = query.list();

Missing ")" and must set parameter value.

Jens
  • 67,715
  • 15
  • 98
  • 113
  • This will not be treated as regex. Ex I have a string "My ARG Students are good to pay for application and content" I want to search good and then i need to put like in loop condition. To avoid this i want to use regex. In short keyword parameter can contain many different keyword. – OPTIMUS Mar 16 '16 at 11:37