[hibernate-dev] Patch for HHH-2308: Adjusting the Outer Join Predicate using Criteria Query

Craig Christophel cbchrist at transgeek.com
Thu Sep 24 11:31:45 EDT 2009


  I've submitted a patch which updates Scott Van Wart's effort with unit tests and documentation changes (en-US) for HHH-2308.  This patch allows users to add Criterion to Criteria aliasing similar to the WITH clause in hql.

List result = session.createCriteria( Student.class )
  .createAlias( "preferredCourse", "pc", Criteria.LEFT_JOIN, Restrictions.eq("pc.courseCode", "HIB-A") )
  .setProjection( Property.forName("pc.courseCode") )

This is useful when sorting large and or complex data inside the database when you intend to only retrieve X number of records from the result-set.  
Without this patch we are forced to perform the same query as follows:

  1.  Query without join constraint and store results.
  2.  Query with an inner join and store results.
  3.  Manually sort in memory with java.

This effectively doubles the workload on the database as the queries are complex even without this join.  It also causes some concern as to memory constraints because the full number of allowable data elements must be loaded twice.  I'd love to be able to use HQL to solve this problem, however the search is very dynamic and the Criteria interface has helped to solve the problem much more elegantly.

The file  hibernate-outer-join-criteria-trunk.diff attached to this defect is the latest example on trunk (3.5)


Craig Christophel

More information about the hibernate-dev mailing list