The following blog post shows the direction and gives a concrete query example :
QCustomer customer = QCustomer.customer; Query<Customer> q = pm.newTypesafeQuery(customer); Customer bob = q.filter(customer.firstName.eq("Bob")) .unique(true).execute();
What about queries which return customer.firstName results?
Using the type parameter in the query there are the options of encoding the source type or the projection in the query.
The example is a bit vague, but could be transformed into the following forms
Projection as argument
QCustomer customer = QCustomer.customer; Query q = pm.newTypesafeQuery(customer); Customer bob = q.filter(customer.firstName.eq("Bob")) .unique(true).execute(customer);
What about list typed results? Do we get this type-safe?
Unique flag implicit via projection method
QCustomer customer = QCustomer.customer; Query q = pm.newTypesafeQuery(customer); Customer bob = q.filter(customer.firstName.eq("Bob")) .unique(customer);
The last example is closest to the Querydsl projection usage, and is also the most compact.
These examples manage without a type parameter, since the projection type is given in the end.