[英]QueryDSL code generation for ManyToMany
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. 我在一个大的Hibernate / JPA2应用程序中移植了一些复杂的JPQL查询以使用QueryDSL 2.3.0,而我却陷入其中。
My Client
entity contains 我的
Client
实体包含
@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: QueryDSL代码生成在我的
QClient
类中产生了以下内容:
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. 使用
SimplePath
生成代码不允许我使用in
或contains
方法来查询成员资格。 I think I need a CollectionPath
instead. 我想我需要一个
CollectionPath
。 Is there a way to annotate the Client
class so that QueryDSL uses the correct type for querying a collection? 有没有办法注释
Client
类,以便QueryDSL使用正确的类型来查询集合?
I have an answer. 我有一个答案。 This looks like a bug introduced in QueryDSL 2.2.5, which only happens when working in Eclipse .
这看起来像是在QueryDSL 2.2.5中引入的一个错误,只有在Eclipse中工作时才会发生 。
The correct solution is to not use Eclipse to generate the source (don't enable annotation processing). 正确的解决方案是不使用Eclipse来生成源(不要启用注释处理)。 Instead, I'm using
m2eclipse
and generating the source in Maven. 相反,我正在使用
m2eclipse
并在Maven中生成源代码。
For reference, my first workaround was to extend the generated QClient
class with my own QQClient
class, which adds one member: 作为参考,我的第一个解决方法是使用我自己的
QQClient
类扩展生成的QClient
类,该类添加一个成员:
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.) (
query
是大的查询,这是的一部分。 slr
是实例QQClient
带入外部查询通过左连接)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.