在 QueryDSL 中使用 CollectionExpression
在 QueryDSL 库中,com.mysema.query.types.expr.SimpleExpression
类有一个 SimpleExpression.in(CollectionExpression)
方法应该采用一个应该返回集合的表达式。但我找不到创建 com.mysema.query.types.CollectionExpression
。
我的查询表达式如下所示:
QEvent.event.organization.in(expression)
我希望 表达式
类似于:
QOrganization.organization.country.in("India", "USA")
但第二个表达式的类型为 com.mysema.query.types.expr.BooleanExpression
并且我无法找到将其转换为 com.mysema.query.types.CollectionExpression
。
我查看了 QueryDSL API 文档,但找不到任何相关内容。
In the QueryDSL library, the com.mysema.query.types.expr.SimpleExpression<T>
class has a SimpleExpression.in(CollectionExpression<?, ? extends T>)
method which is supposed to take an expression which is supposed to return a collection. But I cannot find a way to create an object of type com.mysema.query.types.CollectionExpression<?, ? extends T>
.
My query expression looks like this:
QEvent.event.organization.in(expression)
where i want the expression
to be something like:
QOrganization.organization.country.in("India", "USA")
But the second expression is of type com.mysema.query.types.expr.BooleanExpression
and I am unable to find a way to convert it to com.mysema.query.types.CollectionExpression<?, ? extends T>
.
I looked in the QueryDSL API docs but could not find anything relevant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法将 BooleanExpression 转换为 CollectionExpression,其原因与您无法将 java.lang.Boolean 转换为 java.util.Collection 的原因相同。他们不兼容。
下面的表达对你来说意味着什么
你可能会尝试表达这样的东西吗?
或者更简单,
我想您试图描述的是使用子查询的表达式。像这样的
subQuery() 的实现是 Querydsl 后端特定的。如果您使用联接,那么您将获得每个匹配事件-组织组合的一行,并且通过子查询,您将获得组织满足给定约束的唯一事件。
连接与子查询的性能差异是特定于实现的。
您使用哪个 Querydsl 后端? JPA、SQL 还是其他?
You can't convert a BooleanExpression into CollectionExpression, for the same reasons why you can't convert a java.lang.Boolean into a java.util.Collection. They aren't compatible.
What would the following expression mean to you
Do you maybe try to express something like this?
Or simpler
I guess what you tried to describe was an Expression using subqueries. Something like this
The implementation of subQuery() is Querydsl backend specific. If you use a join then you get a row for each matching event - organization combination and with subqueries you get unique events which have organizations meeting the given constraints.
Performance differences of join vs subquery are implementation specific.
Which Querydsl backend do you use? JPA, SQL or something else?
我不认为你可以这样做,无论如何,这在数据库方面没有意义。
您必须使用子查询
I don't think you can do it like that, it wouldn't make sense on the DB side, anyway.
You have to use a SubQuery