hibernate/hibernate-orm — pull request #533 by jonbcard (2013-05-11 22:32:51+00:00)
Title: HHH-6353: Support aliases in Criteria projections and restrictions

This adds support for using named aliases in Criteria `Restrictions` and `Projections` using placeholders. This is useful for complex cases such as writing correlated sub-queries that need access to tables other than the root entity. The `{alias}` placeholder has been left around for the purposes of backwards compatibility.

Here is a simple example intended to show the new syntax that this supports:

List data = session.createCriteria( Course.class, "c" )
.add( Subqueries.exists(
DetachedCriteria.forClass( Enrolment.class, "e" )
.setProjection( Projections.id() )
.add( Restrictions.sqlRestriction(
"lower({c}.code) = {e}.code" ) ) )
).list();

An alternate (simpler) solution for HHH-6353 would simply be to expose alias look-ups on `Criteria`, but that is a less fluid solution IMHO.

Its my hope that this can lead to a solid solution for HHH-2736. I'd like to be able to re-use this placeholder syntax for writing query hints -- AFAIK Oracle expects table aliases to be provided in hints, and unfortunately I don't see that handled in https://github.com/hibernate/hibernate-orm/pull/160 .