Number 上的 QueryDSL Like 操作

发布于 2025-01-06 17:14:28 字数 995 浏览 2 评论 0原文

我必须用通配符搜索数字字段。相应的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆蝶 2025-01-13 17:14:28

您尝试过吗?

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

我会明白为什么 stringValue() 表达式不适用于 OpenJPA。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文