-->
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 by property
PostPosted: Sat Apr 08, 2006 4:54 pm 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
Hello,

I have object with some properties: name, id, category, etc... I want to get all objects but I don't want to get two or more objects with same name property. So, first thing that crossed my mind is distinct, but when using distinct I don't really get my objects, but Strings.

my hql looks like this:

Criteria cr = session.createCriteria("hr.klopa.domain.FoodItem").setProjection(Projections.distinct(Projections.property("name")));

How can I get FoodItem objects distincted by property "name"

FoodItem class looks something like this:

class FoodItem
{
private Long id;
private String name;
.
.
.
// getters and setters...

}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 08, 2006 5:08 pm 
Newbie

Joined: Wed Nov 30, 2005 4:13 pm
Posts: 12
I think you shoud use 'group by name' - it guarantes distinct by name property and you don't have to use projection so you can get objects instead of properties


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 09, 2006 3:23 am 
Beginner
Beginner

Joined: Sat Feb 18, 2006 6:24 am
Posts: 23
jbialobr wrote:
I think you shoud use 'group by name' - it guarantes distinct by name property and you don't have to use projection so you can get objects instead of properties


Yes, that's it. Just what I need. Thank you!


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.