Reputation: 93
Hello I got stuck a little bit with querydsl (+hibernate 4.2.3 and postgresql). Generally it works pretty well, but then i have one predicate built like this:
QUser user = QUser.user;
....
predicate = and(predicate,
user.userType.in(userTypes)
.or(user.customer.userType.in(userTypes)));
Now the problem is that user does not always have customer. Querydsl generates sql with cross join to customer table, and when user does not have customer this query returns zero entries even though those entries should be returned. This customer has left join (modified spring data a bit to allow join fetch fields) but for it still creates additional cross join. Any ideas how to write such a query?
Upvotes: 2
Views: 1419
Reputation: 22200
I expect the user.customer traversal to create the additional join.
The following query should work
query.from(user)
.leftJoin(user.customer, customer)
.where(user.userType.in(userTypes).or(customer.userType.in(userTypes)));
Upvotes: 2