This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Hibernate query left join  RSS feed

 
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!
 
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
Boost this thread!