-1

I'm tired, my eyes are aching, I've done my research but with no hope, I can't still perform left outer join in hql.

Doing this in native sql is very easy, why HQL just don't add a feature like in sql left outer join.

I'm lost here! I need help if anyone can give me a step by step tutorial on how to perform a simple left outer join in HQL.

Charles
  • 50,943
  • 13
  • 104
  • 142
Jc dev
  • 355
  • 1
  • 6
  • 15
  • @Maheep, it is entirely inappropriate to add your own questions to someone else's. Ask a new question with all of the information required instead. – Charles Oct 14 '13 at 17:24
  • @Charles, I have the same question which OP had asked a year ago, and I updated the question based on OP's comment in the given answer. – Maheep Oct 15 '13 at 06:51

1 Answers1

1

And why don't you read the documentation, where left outer joins are discussed, explained, and where you will even find examples?

from Cat as cat
inner join cat.mate as mate
left outer join cat.kittens as kitten
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • 1
    actually, I dont understand that example, where is the second table there? – Jc dev Mar 01 '12 at 00:07
  • 1
    actually, I dont understand that example, where is the second table there? as I can see there is only one table which is Cat. And what is this line : cat.kittens as kitten? is that the second table? how could that be,? is there some kind of mapping that I need to do? – Jc dev Mar 01 '12 at 00:15
  • One table or two tables doesn't matter. What matters is the association between entities. A Cat has many kittens. Just as Category has many Products, or an Invoice has many Lines. HQL doesn't work on tables. It works on entities having associations with other entities. – JB Nizet Mar 01 '12 at 07:54
  • 2
    Same here... I do not understand any example from the documentation because... 1. They are extremely abstract. Is mate,kittens another table? 2. We get a List from the query.list(), what would the list contain? An object with Cat attributes or mate attributes? – SSG Sep 18 '12 at 17:44
  • @SSG: as I said: tables only matter when mapping the entities and their associations. When you do a HQL query, what metters is entities and their association. Not how they're mapped to tables. If the query selects cats, you will get a list of cats. If the query select cat.name and cat.color, you will get an list of arrays of two elements: the name and the color. It's quite intuitive if you use a select clause. I advise to always use one, even if HQL doesn't require it. It's more readable, and more portable, since JPA requires a select clause. – JB Nizet Sep 18 '12 at 21:33
  • but what if the class I designed is reversed by tool from database tables. Unlike class which one class object contain another class's object(for exmaple Cat have a Kitten), the tables don't have this kind of 'Containing' relationship, what should I do to achieve LEFT JOIN of two tables in this case? – Allan Ruin Nov 24 '13 at 05:07