Question

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?

Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top