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. Interface based usage

Whenever possible, use interface based query references : e.g. JDOQLQuery for JDO and HQLQuery for HQL

3.3.3. Custom query extensions

TODO

3.3.4. 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 HQL usage :

 
protected HQLQuery from(EntityPath<?>... o) {
    return new HqlQueryImpl(session).from(o);
} 

For JDO usage :

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