From: Sylvain T. (JIRA) <no...@at...> - 2006-05-04 13:46:35
|
[ http://opensource.atlassian.com/projects/hibernate/browse/HB-520?page=comments#action_22991 ] Sylvain Tremblay commented on HB-520: ------------------------------------- I have been working on a new Projection called RootProjection which can be used to solve this problem. This projection can be compared to the PropertyProjection but all fields from the Root criteria are returns. You can then set the projection on the Criteria and chain it with the Distinct Projection: Criteria myCriteria = mySession.createCriteria(MyRootClass.class); myCriteria.createCriteria("association1").createCriteria("association2)......add(Restrictions.eq("someField", "someValue"); myCriteria.setProjection(Projections.distinct(Projections.RootProjection())); The select generated will then look like this: select root.field1, root.field2, .... from root inner join association1......inner join associations2........where.......... Then you use the myCriteria.list() to get DISTINCT root entities. However to make this work minor changes needs to be done in Hibernate. I will be submitting a patch so this gets integrated in future version. Sylvain > Add Distinct to Criteria API > ---------------------------- > > Key: HB-520 > URL: http://opensource.atlassian.com/projects/hibernate/browse/HB-520 > Project: Hibernate2 > Type: New Feature > Components: core > Versions: 2.1 rc1 > Environment: Hibernate 2.1+, (Any DB) > Reporter: Stephen Owens > Priority: Minor > > > Need the ability to specify that results of a Criteria query should be 'DISTINCT', especially when joining to a collection. So the Criteria equivalent of the HQL statement > "select distinct parent from Parent as parent join Parent.children as child where child.age>5" -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |