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) ");
2
  • Related : Regex query in Hibernate Commented Mar 15, 2016 at 8: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 Commented Mar 15, 2016 at 9:00

2 Answers 2

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.

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

Comments

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.

1 Comment

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.

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.