• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate query left join

 
Cj Recto
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can find information about joins in hql here.

Hope that helps.

Have fun,
Oli
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic