If Criteria API is the best choice for dynamicly building queries, for user-configured reports, for example, then it should be easier to
add nested properties to the criteria.
Currently, you must createAlias() or createCriteria() for each association
in the query. Because there is no way to 'query' the Criteria object for
existing aliases, the application developer must keep track of aliases in order to avoid duplicate associations throwing a QueryException.
HQL implicitly resolves these associations. It is less convenient and more error-prone to use HQL to generate where and order by clauses, but associations are easier.
HQL:
"select my.friend.name from Person my"
Criteria API:
criteria.createCriteria("friend"); //without this, query will fail.
projectionList.add(Projections.property("friend.name"));
criteria.setProjection(projectionList);
The code that checks if "friend" has already been added has been omitted.
JIRA?
|