exkog wrote:
I would really like to construct queries with Criteria in Hibernate, because of it's clear and consistent handling.
I'm in the same situation you are in terms of wanting to construct Criteria queries programmatically, and I'm currently running up against this same issue (the 'duplicate association'). I'm trying to build a Criteria query programmatically based on a set of criteria values passed into a function. The function must look through these values and add the criteria as needed. The entity I am querying for contains other entities as properties, some of which contain entities themselves, etc.
This seems like a pretty severe limit on the functionality of Criteria queries. Am I correct in assuming that what has been said above means you can not do something like this? :
Code:
// Assume these are valid collections:
Collection aZipCodeCollection;
Collection aCityNameCollection;
Criteria theCrit = theSession.createCriteria( User.class );
theCrit.createCriteria( "address" )
.add( Restrictions.in( "zipcode", aZipCodeCollection ) );
theCrit.createCriteria( "address" )
.add( Restrictions.in( "city", aCityNameCollection ) );
...I
do realize that you can accomplish the same thing by doing the following:
Code:
theCrit.createCriteria( "Address" )
.add( Restrictions.in( "zipcode", aZipCodeCollection ) )
.add( Restrictions.in( "city", aCityNameCollection ) );
...however, if you are building a set of Criteria programmatically it is much more complicated to determine when it would be necessary to do this, especially when you are dealing with a large number of Criteria that may or may not affect a particular property (in this case, an object with multiple properties) within an entity.
I noticed a new JIRA was created a few weeks ago:
http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1048?page=all
...is this a fix for this particular issue?
IMO, once this issue and the lack of the ability for Criteria queries to use the second-level object cache (i.e., the lack of functionality equivilant to Query's iterate() ) are resolved, the Criteria API will officially be rocking! =)