I\'m looking for a builder for HQL in Java. I want to get rid of things like:
StringBuilder builder = new StringBuilder()
.append(\"select stock from \")
For a type-safe approach to your problem, consider Querydsl.
The example query becomes
HQLQuery query = new HibernateQuery(session);
List s = query.from(stock, bonus)
.where(stock.someValue.eq(bonus.id))
.list(stock);
Querydsl uses APT for code generation like JPA2 and supports JPA/Hibernate, JDO, SQL and Java collections.
I am the maintainer of Querydsl, so this answer is biased.