-->
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.  [ 5 posts ] 
Author Message
 Post subject: Inner join where property names don't match
PostPosted: Mon Oct 13, 2003 10:45 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
I want to do an inner join across two tables so I can sort the rows in the first by a name value in the second.

The cat/mate example in the documentation isn't much help, because the join is to the same table. The various forum postings I've read aren't much help because the joins there always seem to involve joining via a bound parameter value.

In my own code "INNER JOIN" has no effect, presumably because the two properties/columns involved in the join have different names. If I do the join in the query myself with a "WHERE a.foo = b.bar" it works OK.

So I guess my questions are: a) is this true and b) if it is, is there ever a benefit to the JOIN keywords in HQL, other than as a shorthand?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2003 10:51 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
HQL's join is not like an SQL join, because it uses an implicit join condition. If you need an explicit join condition, you have to use a theta join (where foo.bar = baz.bar).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2003 11:03 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
Perhaps I wasn't clear; my query works with just the WHERE clause, and doesn't need the JOIN keyword in there.

This suggests that JOIN simply acts as a shortcut for the case where the properties being joined have the same name, and other than that has no purpose.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2003 11:07 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can write your query in both styles in SQL. But if you have no association between the classes that are "joined" in HQL, you have to use a theta style "join".

HQL joins are not SLQ joins and yes, if you like, you can see them just as a shortcut "if the parameters have the same name", which is not the whole truth, but sufficent until you are more familiar with HQL. Don't think in tables and columns, think in classes, properties and associations.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2003 11:12 am 
Beginner
Beginner

Joined: Tue Sep 30, 2003 10:09 am
Posts: 34
Location: London, UK
OK, I see. In my case I just needed to join in order to sort the objects from the left side of the join, so that hadn't occurred to me.

Thanks Christian.


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