How to use regular expressions with Hibernate/Oracle

前端 未结 2 1544
春和景丽
春和景丽 2020-12-18 09:35

I\'m trying to implement a web service which accepts a list of strings, each of which is a regular expression. These need to be compared against six columns of a database,

相关标签:
2条回答
  • 2020-12-18 10:14

    Similar working example

     Criterion criterion = Restrictions.sqlRestriction("regexp_like (column_name, ?, 'i')", "(^|\\s)"+searchValue+"($|\\s|.$)", StringType.INSTANCE);
    
    0 讨论(0)
  • 2020-12-18 10:17

    There's nothing in the hibernate docs for performing regular expression queries (using HQL or Criteria queries). The approach using the sqlRestrictions should probably be changed to one of the overloaded methods to avoid a SQL Injection vulnerability.

    Example code:

    Restrictions.sqlRestriction("regexp_like({alias}.NODE_1, ?)", re, Hibernate.STRING)
    
    0 讨论(0)
提交回复
热议问题