-->
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.  [ 5 posts ] 
Author Message
 Post subject: Multiple Objects in List (resultset)
PostPosted: Thu Jun 03, 2004 3:36 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Hi all, I feel pretty stupid asking this, as I know I've done it before and I'm sure I've read it here somewhere before...just that I can't seem to find it. (You know...one of those days)

Anyway, I have an HQL query that returns 2 objects in the List, and I'm trying to remember how to extract each object from within each of the rows.

I think it has something to do with Object arrays or something.

Please, someone, put me out of my misery. :)

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 3:40 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
With an Iterator?
I m not sure that I understand your question:(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 3:44 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Ok, here's the query:
Code:
        Query detailsQuery = lawnetSession.createQuery("SELECT c, lu FROM " +
            LawUser.class.getName() + " AS lu, " + Company.class.getName() + "AS c " +
            "WHERE lu.companyNumber = c.companyNumber AND lu.lawUserNumber = :lawUserNumber");
        detailsQuery.setLong("lawUserNumber", header.getWorkgroup().getBranchid());

And I want to be able to extract "c", and "lu" as Company and LawUser objects respectively, for each row that I get.

:)

-G


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 3:52 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Use this method
createSQLQuery(String sql, String[] returnAliases, Class[] returnClasses)
Look into the Javadoc maybe it will solve your problem


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 4:01 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Heh...when all else fails. RTFM. Or in this case, the docs.

Found this under the Query.list() method:
Quote:
Return the query results as a List. If the query contains multiple results pre row, the results are returned in an instance of Object[].

(Spelling mistake included :) )

Simply do this:
Code:
Object[] row = (Object[]) listResult.get(i);


Then simply extract row[0] as the first object, and row[1] as the second.

Oh well. Thanks for the help. :)

-G


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