jpa本机查询正则表达式与querydsl一样 [英] jpa native Query regexp like with querydsl

查看:508
本文介绍了jpa本机查询正则表达式与querydsl一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的查询语句:

select t.*
  from T_ex_table t
 where regexp_like(t.note,
                   '^(.*[^[:digit:]]+)?([condition])([^[:digit:]]+.*)?$',
                   'n')

如果我在jpa中将它与querydsl(com.querydsl)一起使用(这是scala,并不重要):

And if I use it in jpa with querydsl(com.querydsl) like(this is scala, and it doesn't important):

 @Query(value =
    "select t.*" +
      "  from T_PURCHASE t" +
      " where regexp_like(t.note," +
      "                   '^(.*[^[:digit:]]+)?([?1])([^[:digit:]]+.*)?$'," +
      "                   'n')", nativeQuery = true)
 def getByTrackingNo(trackingNo: String): Purchase

我调试测试时,它总是抛出

While i debug test, it always throw

为方法public abstract Purchase使用命名参数 PurchaseRepository.getByTrackingNo(java.lang.String) 但是在带注释的查询选择"中找不到参数"trackingNo" 来自T_EC_PURCHASE t的t.pt_note,t.tracking_no,其中 regexp_like(t.pt_note,'^(. [^ [:digit:]] +)?({?1})([^ [:digit:]] +.)?$', 'n')'!

Using named parameters for method public abstract Purchase PurchaseRepository.getByTrackingNo(java.lang.String) but parameter 'trackingNo' not found in annotated query 'select t.pt_note, t.tracking_no from T_EC_PURCHASE t where regexp_like(t.pt_note, '^(.[^[:digit:]]+)?({?1})([^[:digit:]]+.)?$', 'n')'!

我错过了什么吗,我该如何解决?

Did i missed something, and how can i fix it.

推荐答案

也许尝试将完整的regexp移至param方法?并在之前构建它.例如:
@Query(value = "select t.* from T_PURCHASE t where regexp_like(t.note, ?1, 'n')", nativeQuery = true)
其中?1-您可以使用必需的参数完全构建正则表达式.

Maybe try to move full regexp to the param method? and build it before. for example :
@Query(value = "select t.* from T_PURCHASE t where regexp_like(t.note, ?1, 'n')", nativeQuery = true)
Where ?1 - yours fully build regexp with required parameters.

这篇关于jpa本机查询正则表达式与querydsl一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆