类似于QueryDSL的操作SimplePath [英] QueryDSL like operation SimplePath

查看:335
本文介绍了类似于QueryDSL的操作SimplePath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似于此问题我想使用我自己的用户定义类型"AccountNumber"来执行SQL"like"操作

Similarly to this question I would like to perform an SQL "like" operation using my own user defined type called "AccountNumber".

定义列的字段的QueryDSL Entity类如下所示:

The QueryDSL Entity class the field which defines the column looks like this:

public final SimplePath<com.myorg.types.AccountNumber> accountNumber;

我尝试使用以下代码在SQL中实现赞"操作,但是在运行查询之前比较类型时会出错:

I have tried the following code to achieve a "like" operation in SQL but get an error when the types are compared before the query is run:

final Path path=QBusinessEvent.businessEvent.accountNumber;
final Expression<AccountNumber> constant = Expressions.constant(AccountNumber.valueOfWithWildcard(pRegion.toString()));
final BooleanExpression booleanOperation = Expressions.booleanOperation(Ops.STARTS_WITH, path, constant);
expressionBuilder.and(booleanOperation);

错误是:

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [7!%%] did not match expected type [com.myorg.types.AccountNumber (n/a)]

有没有人能够使用QueryDSL/JPA组合实现这一目标?

Has anyone ever been able to achieve this using QueryDSL/JPA combination?

推荐答案

最后,我的同事给了我提示,请他们做以下事情:

In the end, I was given a tip by my colleague to do the following:

 if (pRegion != null) {
        expressionBuilder.and(Expressions.booleanTemplate("{0} like concat({1}, '%')", qBusinessEvent.accountNumber, pRegion));
 }

这似乎可以解决问题!

这篇关于类似于QueryDSL的操作SimplePath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆