QueryDSL与Number上的操作类似 [英] QueryDSL Like operation on Number
本文介绍了QueryDSL与Number上的操作类似的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须使用通配符搜索数字字段。相应的JQPL查询将是这样的:
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是这样的字符串:1 ?? 2和e.personNumber是数据库上的数字(H2) 。
numberPattern is a String like this: "1??2" and e.personNumber is a Number on the Database (H2).
如果我用JQPL运行它,它根本没问题但是我不能把它放到queryDSL查询中。
If i run this with JQPL it's no Problem at all but I can't put it into a queryDSL query.
当我尝试
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));
结果将是
Data conversion error converting "1*"; SQL statement:
Caused by: java.lang.NumberFormatException: For input string: "1*"
那么,有没有办法在queryDSL的数字字段上进行类似的操作?
So, is there a way to have a like operation on an number field with queryDSL?
推荐答案
你试试这个吗?
PredicateOperation predicateOperation = new PredicateOperation(Ops.LIKE,
entity.personNumber, Expressions.constant("1%"));
我将看到为什么stringValue()表达式不适用于OpenJPA。
I will see why the stringValue() expression doesn't work for OpenJPA.
这篇关于QueryDSL与Number上的操作类似的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文