File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate - gathering multiple rows single column for two queries Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate - gathering multiple rows single column for two queries" Watch "hibernate - gathering multiple rows single column for two queries" New topic
Author

hibernate - gathering multiple rows single column for two queries

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Hi there,

I have a scenario where in there are two queries in Hibernate something like this
i) select coldata from tablename where id=1 and ind='ABC'
ii) select coldata from tablename where id=1 and ind='XYZ'

Each will have a different output

Currently I have two queries hitting the database. Is there a way where i can reduce this to 1 query and grab both the details in one go

Let me know is there a way to better this.
Reehan Lalkhanwar
Ranch Hand

Joined: Jun 16, 2007
Posts: 106


Thank you,
Reehan
Javid Jamae
Author
Ranch Hand

Joined: May 14, 2008
Posts: 198
Maybe this:



But if you're using Hibernate, you're not selecting column data and you're not querying tables. The whole point of Hibernate is to pull back objects. You probably just want to do an HQL query that looks something like:



Author: JBoss in Action, javidjamae.com, @javidjamae on Twitter
manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Thanks Javid,

-----------
But if you're using Hibernate, you're not selecting column data and you're not querying tables. The whole point of Hibernate is to pull back objects. You probably just want to do an HQL query that looks something like:
-----------

Yes exactly thats what I have in place. Now my question here is how do you iterate the results and identify which value I got for the query parameter "ABC" and for "XYZ" as i need to use them differently
Javid Jamae
Author
Ranch Hand

Joined: May 14, 2008
Posts: 198
Yes exactly thats what I have in place. Now my question here is how do you iterate the results and identify which value I got for the query parameter "ABC" and for "XYZ" as i need to use them differently


This is just basic Java. You get the collection back from your query and then you loop over the data.

 
GeeCON Prague 2014
 
subject: hibernate - gathering multiple rows single column for two queries