aspose file tools*
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
Author

Hibernate query left join

Cj Recto
Greenhorn

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.java
and Address.java

student table:

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

address table:

studentid|studentaddress
------------------------
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

studentid|studentname|studentaddress
------------------------------------
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
Greenhorn

Joined: Mar 09, 2012
Posts: 6
Hi,

You can find information about joins in hql here.

Hope that helps.

Have fun,
Oli
 
jQuery in Action, 2nd edition
 
subject: Hibernate query left join