-->
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: Dynamic table joins
PostPosted: Fri Apr 13, 2007 6:28 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 10:43 am
Posts: 38
Location: Chicago
Is it possible to join tables without defining the table join relation ship in .hbm.xml?

TABLE a
( c1 number, c2 number ) primary_key c1

TABLE b
(b1 number, a_c1 number )

in SQL it would be

SELECT a.c1, a,c2, b.b1, b.a_c1
FROM a INNER JOIN b on a.c1 = b.a_c1

IS there a way to do the above in HQL?

select a, b FROm a INNER join b
WHERE a.c1 = b.a_c1

does not seeem to work?

does anyone know the exact syntax?

_________________
LET IT BE :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 14, 2007 3:42 am 
Beginner
Beginner

Joined: Thu Apr 12, 2007 3:26 am
Posts: 35
Location: Germany
Yes, it is possible. You have to name the tables in your query (as far as I know you can't select the fields with the tablenames):

SELECT table_a.c1, table_a.c2, table_b.b1, table_b.a_c1
FROM a as table_a INNER JOIN b as table_b on table_a.c1 = table_b.a_c1

I think this should work too if the names of the attributes aren't equal:
SELECT c1, c2, b1, a_c1
FROM a INNER JOIN b on c1 = a_c1

Hoeft


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.