Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate - gathering multiple rows single column for two queries

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Javid Jamae
Author
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic