QueryDSL Like operation on Number

北战南征 提交于 2019-12-22 08:34:44

问题


I have to search a number-field with wildcards. The corresponding JQPL query would be like this:

SELECT e From Entity e where e.personNumber LIKE :numberPattern

numberPattern is a String like this: "1??2" and e.personNumber is a Number on the Database (H2).

If i run this with JQPL it's no Problem at all but I can't put it into a queryDSL query.

when I try to

andBuilder.and(entity.personNumber.stringValue().like(numberPattern)

I get a

org.apache.openjpa.persistence.ArgumentException: "str (" bei Zeichen 7 gefunden, erwartet wurde jedoch ["(", "+", ...

If i try to do it like this:

Constant<String> constant = (Constant<String>) Expressions.constant(personNummer);
PredicateOperation predicateOperation = new PredicateOperation(Ops.LIKE, entity.personNumber, Expressions.constant(constant));

the result will be a

Data conversion error converting "1*"; SQL statement:
Caused by: java.lang.NumberFormatException: For input string: "1*"

So, is there a way to have a like operation on an number field with queryDSL?


回答1:


Did you try this

PredicateOperation predicateOperation = new PredicateOperation(Ops.LIKE,
  entity.personNumber, Expressions.constant("1%"));

I will see why the stringValue() expression doesn't work for OpenJPA.



来源:https://stackoverflow.com/questions/9325762/querydsl-like-operation-on-number

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