jpa native Query regexp like with querydsl

断了今生、忘了曾经 提交于 2020-01-06 06:41:12

问题


I have i query statement like this:

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

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

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.


回答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.



来源:https://stackoverflow.com/questions/49984210/jpa-native-query-regexp-like-with-querydsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!