-->
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.  [ 4 posts ] 
Author Message
 Post subject: help in iterating a result set for a particular query
PostPosted: Wed Oct 19, 2005 12:35 pm 
Newbie

Joined: Wed Oct 19, 2005 12:19 pm
Posts: 4
hi,

I tried reading the information on the web and hibernate docs but I could not understand how to iterate through a result set in teh following scenario:

I have 2 tables Customers and Orders.

I created 2 POJOs corresponding to those tables.

Now, I would like to execute a query say (in SQL systax)

Select c.name, c.email, o.orderID, o.OrderName from customers c and orders o

How should I iterate through the result set as the result set has data pertaining to both CustomerPOJO and OrderPOJO?

Example, if my query was "from CoustomerPOJO" then, I get teh CustomerPOJO Object from teh List. But in thsi case, its is not just one particular object but its a data from both the objects.

Please let me know if I need to do any additional configuration in the hibernate config file.

Thanks for your help!


Top
 Profile  
 
 Post subject: q
PostPosted: Wed Oct 19, 2005 1:00 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
One tip: to successfully use H you should try thinking in terms of objects and properties, and not in the terms of records and columns.

Now, lets assume that Order object has property of Customer type and the property is mapped in H mapping files, then the HQL will be

From Order o where o.something = :someparam

Then you probably want just a list of property values and do not want to instantiate all those stinking objects :)

Then HQL will look like:
Select o.property, o.customer.property from Order o where o.something = :someparam

Such query returns list of arrays to iterate through.
http://www.hibernate.org/hib_docs/v3/re ... ing-scalar


and of course you can escape into SQL
http://www.hibernate.org/hib_docs/v3/re ... rysql.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 1:11 pm 
Newbie

Joined: Wed Oct 19, 2005 12:19 pm
Posts: 4
Hello Konstantin ,

Thanks for taking time to reply. Your tip really helped me in understanding hibernate better than any other document.

Thanks a ton!


Top
 Profile  
 
 Post subject: You are welcome!
PostPosted: Wed Oct 19, 2005 1:35 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Enjoy Hibernate, and do not forget to rate ;)

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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