Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa queryDSL中的正则表达式匹配_Jpa_Querydsl - Fatal编程技术网

Jpa queryDSL中的正则表达式匹配

Jpa queryDSL中的正则表达式匹配,jpa,querydsl,Jpa,Querydsl,我正在尝试执行一个查询,以便在SQL中重现以下内容: where REGEXP_LIKE(variable, regular_expression); 我尝试使用match谓词和match操作符,但似乎在这两种情况下,表达式都被转换为like regex-like方法将拒绝与regex语法对应的任何“*”或“[”,并将抛出QueryException: “12-*34”无法转换为类似形式” 有没有办法在QueryDSL上执行此操作 编辑: 数据库是oracle11g 使用的querydsl库

我正在尝试执行一个查询,以便在SQL中重现以下内容:

where REGEXP_LIKE(variable, regular_expression);
我尝试使用match谓词和match操作符,但似乎在这两种情况下,表达式都被转换为like

regex-like方法将拒绝与regex语法对应的任何“*”或“[”,并将抛出QueryException:

“12-*34”无法转换为类似形式”

有没有办法在QueryDSL上执行此操作

编辑: 数据库是oracle11g

使用的querydsl库是:com.mysema.querydsl版本3.6.9

随着SpringData1.12的发布(querydsl 4支持),我将在迁移到com.querydsl的最新版本(4)后重试

以下是相关代码:

String telRegex = "";
            if (this.tel.length() > 1)
            {
                char[] chars = this.tel.toCharArray();
                telRegex += chars[0];
                for (int i = 1; i < chars.length; i++)
                {
                    // NB can't make regex to work as special characters are banned cf. ExpressionUtils.regexToLike
                    //telRegex += "-*" + chars[i];
                    telRegex += "" + chars[i];
                }
            }
            else
            {
                telRegex = rechercheDto.getTelephone();
            }

            telRegex = "^" + telRegex + "$";

            // query
            predicate.and($(contact.getTel()).isNotNull())
            .and(
                $(contact.getTel()).matches(telRegex )
            );
String telRegex=”“;
如果(此.tel.length()大于1)
{
char[]chars=this.tel.toCharArray();
telRegex+=chars[0];
for(int i=1;i
JPA查询中的模式匹配是使用
LIKE
完成的,并且仅限于
%
。查询DSL将尝试将正则表达式转换为
LIKE
表达式

来自
StringExpression.matches(String)

一些实现(如Querydsl JPA)将尝试将正则表达式转换为类似的形式,并在失败时抛出异常


要使用REXGEP表达式执行WHERE子句,我使用以下代码

jpaQuery 
  = jpaQuery
      .where
        (Expressions.booleanTemplate
          ("function('REGEXP_LIKE',{0},{1}"
          ,qTable.ctcTireLineName
          ,sRegex
          )
        );
我使用QueryDSL 3.7.2


我刚刚尝试过使用sRegex=“^(EA | SPORT)。*”它在Java 8中运行良好。

您使用的是什么数据库?嗨,Robert,我使用的是Oracle 11gIs,它是您正在匹配的字符串?我尝试调用
StringExpression的
公共布尔表达式匹配(String regex)
使用Oracle 11G和SQL进行清单显示类似于
regexp\u
。代码类似于
where(tableName.columnthatsString.matches(“^foo$”)
如果这没有帮助,我们可以获取您正在使用的querydsl版本和代码吗?@RobertBain添加了编辑中使用的vesion。我尝试了一个与您一样的查询,得到了:com.mysema.query.QueryException:“^0493$”无法转换为like form对我来说,解决方案是执行近似的
like
,然后用java过滤结果
String.matches(String)
您说得对,谢谢。不过,有关解决方法,请参阅schlebe的评论(7/04)