-->
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: How to retrieve unique column values from an object?
PostPosted: Mon Mar 15, 2004 3:18 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
Hi I've got a POJO with a bunch of String's etc inside it, mapped as persistent. I am creating an app that does query's on the values inside that object so for instance I have a String field state. I want my query box to show only the values for state currently in all of my objects. Is it possible to retrieve a list of all the values of a property of a persistant object?

If that wasnt clear enough:

<hibernate-mapping>
<class name="FlexReference" table="flexReference">
<id name="id" type="long" unsaved-value="null">
<generator class="identity"/>
</id>
<property name="address"/>
<property name="region"/>
<property name="state"/> <--- String value
<property name="zip"/>
</class>
</hibernate-mapping>

There's my object, I would like a list of all the UNIQUE values in the state column of my object..

Thanks in advance,
David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 4:08 pm 
Regular
Regular

Joined: Wed Dec 17, 2003 1:58 pm
Posts: 102
answered my own question if anyone finds this down the road:

List regions = session.find("select distinct ref.region from FlexReference ref order by ref.region");

and since that property was a string it'll produce a list of strings.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 4:57 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you can also do session.find("select distinct ref.region, attrB from FlexReference ref order by ref.region");
it will return a list of Object[]


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.