Hi.
You can't enforce a left join at this level in Querydsl. To get a left join you need to left join explcitly in the query construction like this :
query.from(category)
.leftJoin(category.parent, parent)
.list(new ConstructorExpression(someClass,
category.name, parent))
Br,
TImo
On Sat, Oct 20, 2012 at 1:34 PM, Querydsl on behalf of Jose Miguel Samper
<querydsl+noreply-APn2wQf7_6Utszs...@googlegroups.com> wrote:
I'm using ConstructorExpression.create programmatically to generate constructor projections as explained in the reference documentation, section 3.1.4.
My main JPA Entity is
@Entity
public class Category {
...
private String name;
@ManyToOne
private Category parent;
...
}
When a constructor argument is a JPA relationship (the "parent" field), the generated SQL uses an INNER JOIN, but I need a LEFT JOIN, as the field could be NULL.
Is there any way to force a LEFT JOIN instead of an INNER JOIN?
With JPA CriteriaBuilder it is acomplished as in the following example (look at "parent" argument):
...
root = query.from(Category.class);
CompoundSelection constructor = criteriaBuilder.construct(MyProjection.class,
root.get("name")
root.join("parent", JoinType.LEFT));
query.select(constructor);
...
Regards,
Jose Samper
--
Timo Westkämper
Mysema Oy
+358 (0)40 591 2172
www.mysema.com