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.  [ 2 posts ] 
Author Message
 Post subject: how to get the data from 2 tables
PostPosted: Tue Apr 10, 2007 8:29 am 
Newbie

Joined: Tue Apr 10, 2007 7:31 am
Posts: 3
Quote:

hi to all

please provide me help regording this

i need to get data from 2 tables. for that i build query like this:-



Query query= session.createQuery("select a.name,u.phone from com.bosch.Admin a, com.bosch.User u where u.no=a.adminid");

ArrayList al=(ArrayList) query.list();

i con't able to type cast into either User or Admin.

What I can do now .

please give me reply

thanking you,
Nagendra



Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 10, 2007 10:48 am 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
User and Admin objects will have properties other than username and phone.

Typically Hibernate would cat queries that fetch only a sub-set of the properties of 1 or more tables as an Object[].

You can instead do this:
Code:
Query query= session.createQuery("select a from com.bosch.Admin a, com.bosch.User u where u.no=a.adminid");


This list will just be only "Admin" objects. However if you need both User and Admin objects, you will have to define the correct mapping between user and admin objects and then either fetch parent object.

So for e.g., if Admin has a one-to-many (bidirectional) relationship with User, then define that mapping and use the following HQL:

Code:
Query query= session.createQuery("from com.bosch.Admin");


However if your Admin is a sub-class of User etc. then you will have to map the object using one of the inheritance strategies provided by Hibernate.

Please provide the HBM mapping files to provide additional thoughts

_________________
--------------
Don't forget to Rate the post


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