3.3. Best practices

3.3.1. Use default variable of the Query types

Use the default variables of the query types as much as possible. The default variables are available as static final fields in the query types. The name is always the decapitalized version of the simple type name. For the type Account this would be account :

     
public class QAccount extends EntityPathBase<Account>{
      
    public static final QAccount account = new QAccount("account");
    
}

Querydsl query types are safe to re-use, and by using Querydsl default variables you save initialization time and memory.

3.3.2. Custom query extensions

TODO

3.3.3. DAO integration

A practice which we have found to be very easy to use is to provide factory methods for Query instances in DAO implementations in the following form.

For JPA usage :

 
protected JPAQuery from(EntityPath<?>... o) {
    return new JPAQuery(entityManager).from(o);
} 

For JDO usage :

protected JDOQLQuery from(EntityPath<?>... o) {
    return new JDOQLQueryImpl(persistenceManager).from(o);
}