-->
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 problem
PostPosted: Thu Jun 24, 2004 9:50 pm 
Newbie

Joined: Thu Jun 24, 2004 9:36 pm
Posts: 1
Hi,
I have tried to do a distinct query in Hibernate but it still keeps giving me duplicates.

My query is SELECT distinct ROLENAME, ROLEID FROM A_TABLE

All I want is the ROLENAME to be distinct but it keeps giving me duplicate role names. This is supposed to be a very simple query. I even tried a native SQL query with the same result.

Here's my code :
Query query = session.createQuery(
"SELECT DISTINCT A.roleName, A.secAppRoleID from secAppRole A");

This returns a list of object arrays. The rolename is still NOT distinct.

---------------
Native query attempt -- I tried the native sql query like this without much luck. It still gives me 2 rolenames which are the same.

Query query = session.createSQLQuery(
"SELECT DISTINCT {A}.ROLE_NAME AS {A.roleName}, " +
" {A}.SEC_APP_ROLE_ID AS {A.secAppRoleID} from SEC_APP_ROLE {A} ", "A", SecAppRole.class );

Could someone pls help me get this simple thing working.

Vinh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 24, 2004 9:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate has the same semantics as SQL. Get a book on SQL and read it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 25, 2004 7:38 am 
Newbie

Joined: Wed Apr 14, 2004 6:44 am
Posts: 1
Collection coll = new ArrayList();
Session sess = HibernateUtilSourceGeneral.currentSession();
iter = sess.iterate( "SELECT DISTINCT o.levelId from Member o where o.levelId IS NOT NULL");

while (iter.hasNext()){
Object row = (Object) iter.next();
coll.add(row);
}

Hopefully this helps
Nathalie


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.