Search code examples
regexdatabasejpaeclipselink

EclipseLink REGEXP?


I have to search records from database based on regular expressions on a column value. I am using JPA for persistent and there is no support for REGEXP in JPA, I googled it and came to know that EclipseLink suuports REGEXP, I know that it is a compromise with portability but I am not getting any way out.

I would like to ask following regarding EclipseLink REGEXP support -

  1. How to use REGEXP supported by EclipseLink
  2. In What cases support is guaranteed for REGEXP
  3. If not guaranteed what is the behavior on failure

Thanks in advance


Solution

  • The EclipseLink documentation for the expression is found here: http://www.eclipse.org/eclipselink/api/2.4/org/eclipse/persistence/expressions/Expression.html#regexp(java.lang.String)

    And you can check out the blog post http://java-persistence-performance.blogspot.com/2012/05/jpql-vs-sql-have-both-with-eclipselink.html which lists some of the databases that support REGEXP, but it comes down to the database. EclipseLink will issue the SQL, and it is up to the database to handle it and control the behavior. If it can't, it will likely throw an exception stating there is an error in the SQL. For specifics on how REGEXP works, you should check your database docs.