Number 上的 QueryDSL Like 操作
我必须用通配符搜索数字字段。相应的 JQPL 查询将如下所示:
SELECT e From Entity e where e.personNumber LIKE :numberPattern
numberPattern 是一个如下所示的字符串:“1??2”,而 e.personNumber 是数据库 (H2) 上的数字。
如果我使用 JQPL 运行它,那根本没有问题,但我无法将其放入 queryDSL 查询中。
当我尝试时,
andBuilder.and(entity.personNumber.stringValue().like(numberPattern)
我得到一个
org.apache.openjpa.persistence.ArgumentException: "str (" bei Zeichen 7 gefunden, erwartet wurde jedoch ["(", "+", ...
如果我尝试这样做:
Constant<String> constant = (Constant<String>) Expressions.constant(personNummer);
PredicateOperation predicateOperation = new PredicateOperation(Ops.LIKE, entity.personNumber, Expressions.constant(constant));
结果将是 a
Data conversion error converting "1*"; SQL statement:
Caused by: java.lang.NumberFormatException: For input string: "1*"
那么,有没有办法使用 queryDSL 对数字字段进行类似操作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过吗?
我会明白为什么 stringValue() 表达式不适用于 OpenJPA。
Did you try this
I will see why the stringValue() expression doesn't work for OpenJPA.