ManyToMany 的 QueryDSL 代码生成

发布于 2024-12-22 19:06:31 字数 738 浏览 3 评论 0原文

我正在将一些复杂的 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 的代码生成没有'不允许我使用 incontains 方法来查询成员资格。我想我需要一个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 技术交流群。

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

发布评论

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

评论(1

第几種人 2024-12-29 19:06:31

我有一个答案。这看起来像是 QueryDSL 2.2.5 中引入的错误,仅在 Eclipse 中工作时才会发生

正确的解决方案是不使用 Eclipse 生成源代码(不启用注释处理)。相反,我使用 m2eclipse 并在 Maven 中生成源代码。


作为参考,我的第一个解决方法是使用我自己的 QQClient 类扩展生成的 QClient 类,这会添加一个成员:

public final ListPath<Group, QGroup> fixedgroups = 
                  createList("groups", Group.class, QGroup.class);

此时,与我的原始查询等效的是

QGroup g = QGroup.group;
JPQLSubQuery subquery = new JPQLSubQuery().from(g);
subquery = subquery.where(slr.fixedgroups.contains(g), 
    g.description.upper().like("%" + group.toUpperCase() + "%"));
query = query.where(subquery.exists());

:( 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 own QQClient class, which adds one member:

public final ListPath<Group, QGroup> fixedgroups = 
                  createList("groups", Group.class, QGroup.class);

At that point the equivalent to my original query is:

QGroup g = QGroup.group;
JPQLSubQuery subquery = new JPQLSubQuery().from(g);
subquery = subquery.where(slr.fixedgroups.contains(g), 
    g.description.upper().like("%" + group.toUpperCase() + "%"));
query = query.where(subquery.exists());

(query is the larger query this is part of. slr is an instance of QQClient brought into the outer query by a left join.)

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