I would like to know if the order that I declare the joins in a HQL query affects the result and the generated query. My idea is to create a template HQL to reduce the code. Something like this:
private String mountTemplateQuery(final String joins) {
final StringBuilder sbQuery = new StringBuilder("select distinct p ");
sbQuery.append("from Order p ");
sbQuery.append("inner join fetch p.items item ");
sbQuery.append("inner join fetch p.contact con ");
sbQuery.append("inner join fetch item.product prod ");
sbQuery.append("left join fetch p.delivery e ");
sbQuery.append("left join fetch p.paymentType pe ");
sbQuery.append("left join fetch item.schedule agend ");
sbQuery.append("left join fetch item.address endPosto ");
sbQuery.append(joins); // Here are the order specific joins needed by other methods.
sbQuery.append(// "where" and "order" clauses here);
return sbQuery.toString();
}
I’m woking in a legacy code so, this is the best I can do for now as there are lots of Ctrl+C/Ctrl+V here.
Thanks in advance!