Reputation: 1139
Say you have a QueryDSL query as follows:
JPQLQuery query = new JPAQuery(em);
QUser user = QUser.user;
QLocation location= QLocation.location;
query.from(User).innerJoin(user.location, location).where(user.name.eq("Giuseppe").and(location.name.eq("Vatican City")));
How is that different (functionally) from the following?
JPQLQuery query = new JPAQuery(em);
QUser user = QUser.user;
query.from(User).where(user.name.eq("Giuseppe").and(user.location.name.eq("Vatican City")));
It seems to me that both are able to resolve the condition stating that the user's location must be Vatican City. Also, both return objects that allow navigation across the object graph.
So is there any difference? Why not just use the second, more compact one?
Edit: they generate different JPQL, that's for sure, but I'm not sure that the end result is any different. Why would we ever want to explicitly list what join we're doing?
Edit 2: Seems like they might be identical... http://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html/ch11.html#d5e2888
Upvotes: 4
Views: 1655
Reputation: 1139
For the record, the implicit joins in the where clauses perform inner join. According to the QueryDSL forum, you'd use the explicit joins when you want to reuse joins or use other join types beside inner join. Otherwise, you can just use the where clauses.
Upvotes: 4