File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate query left join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate query left join" Watch "Hibernate query left join" New topic

Hibernate query left join

Cj Recto

Joined: Mar 02, 2012
Posts: 26
Hellow guys, I've search trough the net but still I'm failed to do a left join in HQL.

So I decided to post here in Coderanch hoping someone might be able to help me.

Ok, I have a very simple example here.
Let's say I have two tables student and address table. They are mapped as

student table:

000000001|mark reyes
000000002|rico go
000000003|alvin rich
000000004|freddy gun

address table:

000000001|apple street.
000000002|mango street.
000000003|banana street.

Ok, in sql, to left join this two table you write:

select stu.*, addr.studentaddress from
student stu left join
address addr on (stu.studentid=addr.studentid);

so I will get

000000001|mark reyes |apple street
000000002|rico go |mango street
000000003|alvin rich |banana street
000000004|freddy gun |

Then how would I do that in hql?
I've seen different HQL codes on doing a left join, I tried them, but no luck for me.
I think I still need to do some kind of mapping relationship, but I dont know how?

I'm using JPA to map my class.

I will greatly appreciate your help!
Thank you in advance!
Oli Wurster

Joined: Mar 09, 2012
Posts: 6

You can find information about joins in hql here.

Hope that helps.

Have fun,
I agree. Here's the link:
subject: Hibernate query left join
jQuery in Action, 3rd edition