How to use regular expressions with Hibernate/Oracle

前端 未结 2 1545
春和景丽
春和景丽 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: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)
    

提交回复
热议问题