-->
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.  [ 3 posts ] 
Author Message
 Post subject: Distinct and Projections
PostPosted: Thu Jan 04, 2007 4:31 pm 
Newbie

Joined: Thu Jan 04, 2007 4:08 pm
Posts: 2
I'm trying to perform the equivalent of the SQL distinct keyword on my Criteria object, but am having little luck finding an example solution online. Here's what I've found so far as an example (from http://kickjava.com/src/org/hibernate/t ... t.java.htm), but it doesn't compile.

Code:
s.createCriteria(Enrolment.class)
             .setProjection( Projections.distinct( Projections.projectionList().add( Projections.property("studentNumber"), "stNumber" )



Here's what I'm trying to do.

Code:
Criteria criteria = session.createCriteria(MyClass.class);
criteria.setProjection(Projections.distinct(Projections.projectionList().add(Projections.property(Table.FIELD_NAME))));
criteria.addOrder(Order.desc(Table.FIELD_NAME));
criteria.setMaxResults(50);


The IDE complains...

The method distinct(ProjectionList) is undefined for the type Projections

I've tried using this methodology as opposed to the projections methodology...

Code:
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);


... but what I'm finding is that the distinct keyword is not included in the query. Therefore 50 results are returned but then the dupes are pulled out which leaves me with only 43 (lets say) results. The client is requesting that 50 distinct results are returned.

Does anyone have any experience doing this? Thanks a ton!


Top
 Profile  
 
 Post subject: org.hibernate.criterion.Projections
PostPosted: Fri Jan 05, 2007 5:05 am 
Beginner
Beginner

Joined: Wed Aug 31, 2005 3:54 am
Posts: 45
Can you verify that the Projection class is the following :
org.hibernate.criterion.Projections

What is your Hibernate version ?

Don't forget to rate ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 1:18 pm 
Newbie

Joined: Thu Jan 04, 2007 4:08 pm
Posts: 2
My apologies. Yes. That is the class I'm attempting to use.

Version: 3.0.1

I don't have the API for this version and was trying to use the 3.2.1 version API to solve the issue. Evidently, the Projections.distinct method is newer than 3.0.1. Business is hesitant to upgrade to 3.2 until we can determine the impact on other projects so I'm needing a 3.0.1 (or compatible) solution.

Thanks for the reply.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.