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 \")
It looks like you want to use the Criteria query API built into Hibernate. To do your above query it would look like this:
List stocks = session.createCriteria(Stock.class)
.add(Property.forName("id").eq(id))
.list();
If you don't have access to the Hibernate Session yet, you can used 'DetachedCriteria' like so:
DetachedCriteria criteria = DetachedCriteria.forClass(Stock.class)
.add(Property.forName("id").eq(id));
If you wanted to get all Stock that have a Bonus with a specific ID you could do the following:
DetachedCriteria criteria = DetachedCriteria.forClass(Stock.class)
.createCriteria("Stock")
.add(Property.forName("id").eq(id)));
For more infromation check out Criteria Queries from the Hibernate docs