-->
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: Inner joins in Hibernate: Example request
PostPosted: Fri Dec 16, 2005 2:35 am 
Newbie

Joined: Fri Dec 16, 2005 12:31 am
Posts: 6
How does one perform an inner join between two tables in Hibernate using (say) their common column?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 2:42 pm 
Newbie

Joined: Mon Dec 12, 2005 11:37 am
Posts: 14
Well you can use HQL to do a inner join -

from Parent inner join Parent.child


Top
 Profile  
 
 Post subject: No associations
PostPosted: Sat Dec 17, 2005 4:15 am 
Newbie

Joined: Fri Dec 16, 2005 12:31 am
Posts: 6
Hi - thanks for the quick response.

The two tables (read objects) do not have an association between them.
Hence I cannot do a join based on a 'child' object.

These are two non-associated classes that I'd like to join. My purpose is to retrieve records from one table based on common data between the two tables.

Any more inputs will be appreciated! Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 5:39 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Something like this will work

List allObjs = session.createQuery("from Test1 t1, Test2 t2 " +
"where t1.col1 = t2.col1").list();

assuming Test1 and Test2 are two classes which have col1 to be same between them. They dont have to be the primary key either. Note that the above will return objects from both the classes, You can trim them accordingly.


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.