ManyToMany 的 QueryDSL 代码生成
我正在将一些复杂的 JPQL 查询移植到大型 Hibernate/JPA2 应用程序中以使用 QueryDSL 2.3.0,但我陷入了困境。
我的 Client
实体包含
@ManyToMany
private List<Group> groups;
我现有的查询片段是
EXISTS(SELECT g FROM Group g WHERE g MEMBER OF slr.groups AND
UPPER(g.description) LIKE :group)
QueryDSL 代码生成在我的 QClient
类中生成了以下内容:
public final SimplePath<java.util.List<Group>> groups =
createSimple("groups", java.util.List.class);
使用 SimplePath
的代码生成没有'不允许我使用 in
或 contains
方法来查询成员资格。我想我需要一个CollectionPath
。有没有办法注释 Client
类,以便 QueryDSL 使用正确的类型来查询集合?
I'm porting some complex JPQL queries in a large Hibernate/JPA2 application to use QueryDSL 2.3.0, and I'm stuck on one.
My Client
entity contains
@ManyToMany
private List<Group> groups;
My existing query fragment is
EXISTS(SELECT g FROM Group g WHERE g MEMBER OF slr.groups AND
UPPER(g.description) LIKE :group)
The QueryDSL code generation has produced the following in my QClient
class:
public final SimplePath<java.util.List<Group>> groups =
createSimple("groups", java.util.List.class);
The code generation using SimplePath
doesn't let me use the in
or contains
methods to query membership. I think I need a CollectionPath
instead. Is there a way to annotate the Client
class so that QueryDSL uses the correct type for querying a collection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个答案。这看起来像是 QueryDSL 2.2.5 中引入的错误,仅在 Eclipse 中工作时才会发生。
正确的解决方案是不使用 Eclipse 生成源代码(不启用注释处理)。相反,我使用
m2eclipse
并在 Maven 中生成源代码。作为参考,我的第一个解决方法是使用我自己的
QQClient
类扩展生成的QClient
类,这会添加一个成员:此时,与我的原始查询等效的是
:(
query
是它所属的较大查询,slr
是通过左连接引入外部查询的QQClient
实例。)I have an answer. This looks like a bug introduced in QueryDSL 2.2.5, which only happens when working in Eclipse.
The correct solution is to not use Eclipse to generate the source (don't enable annotation processing). Instead, I'm using
m2eclipse
and generating the source in Maven.For reference, my first workaround was to extend the generated
QClient
class with my ownQQClient
class, which adds one member:At that point the equivalent to my original query is:
(
query
is the larger query this is part of.slr
is an instance ofQQClient
brought into the outer query by a left join.)