-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Projections.distinct(?????). Getting the right entity.
PostPosted: Wed Oct 19, 2005 7:40 pm 
Newbie

Joined: Tue Sep 21, 2004 6:10 pm
Posts: 16
Location: Toronto, Canada
Hibernate version:3.1beta1
Name and version of the database you are using: HSQL-1.8.0.1

Hi there,

I have researching for a while now a way to get distinct entities using the Criteria API.
The only way I have found, so far, is more or less like this:


Code:
Criteria crit = session.createCriteria(Foo.class);
// Adding restrictions to the entities
crit.add(Restrictions.???());
.....
crit.add(Restrictions.???());

// Setting the distinct projection.
crit.setProjection(Projections.distinct( other projection goes in here ));


The problem here is what Projection to use as parameter to Projections.distinct. In this forum I found a post at:

http://forum.hibernate.org/viewtopic.php?t=931731


and the last person to ask is asking exactly what I need.

Quote:

If you have to use a projection in the distinct projection, how do you make it return just the entities you are trying to select in the criteria?


Why is it that Projections.distinct needs to take a Projection for parameter???? or even better; can we have an overloaded version of Projections.distinct that takes no parameter at all?? just like Projections.rowCount()?? or as some one suggested in some of the threads I read before posting; Criteria.listDistinct();

There are many other threads in this forum asking for help regarding this and none of them seem to find a definite solution.

There is one solution that comes to mind that althought it is extremelly inefficient it would work and is to define a ResultTransformer that will take the tuples returned by the Criteria and convert them to the original entity. However, there is functionality in hibernate to do this already... Anyway.. I hope some one can come up with a nice solution.

Cheers 2 you all.

edovale


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 9:43 pm 
Newbie

Joined: Tue Sep 21, 2004 6:10 pm
Posts: 16
Location: Toronto, Canada
Either I am way out of tone or no one has an answer.. I'll bet for the former.
I any case.. I am really interested about finding a way around this. I am willing to submit a patch and in fact I already checked out the code and was looking into the posibility of adding a new constructor to Distinct with no arguments. There are a whole bunch of methods though that I don't know how to implement. If any one from the team could shade some light I'll be very grateful..

thanks.

edovale


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.