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(PEntity<?>... o) {
return new HqlQueryImpl(session).from(o);
}
For JDO usage :
protected JDOQLQuery from(PEntity<?>... o) {
return new JDOQLQueryImpl(persistenceManager).from(o);
}