-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: complex outer join with HQL
PostPosted: Thu Mar 23, 2006 4:38 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Hibernate version:
Hibernate 3

Name and version of the database you are using:
MySQL 5


I would like to generate complex outer joins with HQL.

For example:

(you must assume the usual map files and pojos)

two tables like these:

questions
  • id (PK)
  • question

answers
  • id (PK)
  • idQuestion (FK on questions)
  • idPerson (FK on People)
  • answer



With SQL I can ask for:
Code:
select
   q.question,
   a.answer
from
   question as q
   left outer join answer as a
      on
         a.idQuestion = q.id
         and
         a.idPerson = 666

With it, I can get ALL the questions along with the existing answers of person with id 666.

With HQL I can do something like this:
Code:
select
   q,
   a
from
   question as q
   left outer join q.answers as a


BUT, how I could intro the person restriction?????
This doesn't work
Code:
select
   q,
   a
from
   question as q
   left outer join q.answers as a
where
   a.person = :person

Because it only gives me the questions where exists an answer.

Any hint???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 12:53 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
I found it!

the HQL keyword to do it is with


It's only curiosity but any Hibernate developper could tell me why they choose with instead of on like in SQL.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.