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 \")
Now are also available the standard JPA Type Safe query and an less standard but also good Object Query
Examples:
JPA Type Safe
EntityManager em = ...
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery c = qb.createQuery(Stock.class);
Root = c.from(Stock.class);
Predicate condition = qb.eq(p.get(Stock_.id), id);
c.where(condition);
TypedQuery q = em.createQuery(c);
List result = q.getResultList();
Object Query
EntityManager em = ...
ObjectQuery query = new GenericObjectQuery(Stock.class);
Stock toSearch = query.target();
query.eq(toSearch.getId(),id);
List res = (List)JPAObjectQuery.execute(query, em);