-->
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.  [ 7 posts ] 
Author Message
 Post subject: Hibernate Query for multiple tables
PostPosted: Wed Aug 17, 2005 1:04 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
Hi,
I ran my test cases with a direct table which deals with one table one mapping file one pojo.

If I want to get data from multiple tables for a given identifier do I have to create pojo with attributes quried from multiple tables ?.
Can I right a straight SQL and execute using Hibernate for this scenario?

If a table have association with another table will querying parent table automatically retrieves child table data and returns its pojos ?

Can some one explain me. Thank in advance.

Sudhakar


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 1:18 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
You really need to read the documentation.

http://www.hibernate.org/hib_docs/v3/re ... /#querysql


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 2:24 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
The documentation explains me how to use nativeSQL and the example code deals with one table--one pojo--one mapping file. My other question is with multle tables . Can any one point me to a good documentation for this ?

Thanks
Sudhakar


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 2:27 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
I guess I don't know what's confusing you then. If you're not familiar with joins, head for Google and look up a SQL tutorial. If you already know how joins work, then could you please write up what isn't working for you when you try this through Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 2:35 pm 
Beginner
Beginner

Joined: Thu Apr 14, 2005 11:39 am
Posts: 31
I know the joins but I guess you did not read or undersnad my question.

Here is EX:
TableA, PojoA
TableB, PojoB
TableC,PojoC.

If I wote a native SQL to get data from three tables. What will be the result ? Is it a resultSet or list of pojo's ?.

I hope you are cleard now.

Sudhakar


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 3:19 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
Post you code if you want an exact answer.

You're either going to get back a List of the entities you're querying or a List of Object[]. It depends, and we can't guess what it will be since you still haven't posted mappings or code.


Top
 Profile  
 
 Post subject: Re: Hibernate Query for multiple tables
PostPosted: Tue Jan 03, 2012 5:35 am 
Newbie

Joined: Tue Jan 03, 2012 5:21 am
Posts: 1
Hi , I am new to Hibernate, but am facing the above problem.
here is my code details :
Code:
Pojo Class                            Table
TravelBatchParticulars --  Travel_Batch
BranchInfo            --     BranchInfo

--There is no primary, foreign key's

My Query is :
String hq1 = " Select batch.BATCH_ID as BATCH_ID , batch.TRAVEL_BATCH as TRAVEL_BATCH, batch.BRANCH_ID as BRANCH_ID
from TravelBatchParticulars batch , BranchInfo info where batch.USER_NAME = info.userid and
batch.BRANCH_ID = info.branch_id " ;
List<TravelBatchParticulars> travelBatchList = new ArrayList<TravelBatchParticulars>();
travelBatchList = session.createQuery(hq1).list();

After executing , Println of travelBatchList.size() showing as 2.
but am not getting which objects present in this list ?
Code:
for(TravelBatchParticulars batchParticular : travelBatchList ) {    // Here System posting the Exception
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.arms.misreport.core.TravelBatchParticulars

Even i tried to change the query. but unable to handle the output object list :
Code:
String hq1 = "  from TravelBatchParticulars batch , BranchInfo info " +
   "where batch.USER_NAME = info.userid and batch.BRANCH_ID = info.branch_id " ;

Here generated hql showing the all columns from both the tables. i need data from first table only.

Thanks in Advance,


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