-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL how to express complex join with two paths.
PostPosted: Wed Mar 23, 2011 6:52 pm 
Newbie

Joined: Wed Mar 23, 2011 5:20 pm
Posts: 3
I've following classes with FK relation:
Q (1:n) S
Q (1:n) A ( n:1 ) S The relation Q-A is optional (and A-S as well).
Think about Questions with predefined Select options (as answers) and a large number of given Answers.

Now I want to have all Q,S,A with Q,S,null when there is no Q-A relation.
In native SQL this is rather straight forward (fragment):
Code:
from Q inner join S on Q.id = S.q_id
left join A on Q.id = A.q_id and A.s_id = S.id

But how to express this in HQL? I got this far:
Code:
from Q q join q.setS s left join q.setA
with Q.setS the OneToMany mapping of Q to S.
But how to bring in the relation between A and S? (I know that in this case a solution via Q-in-S-oj-A exists, but this is a simplification of a complexer problem I have).

An other slightly different pattern is that the relation between A (n:1) S is not a FK relation but an expression. How to take care of that in HQL?

Thanks,
Erik


Top
 Profile  
 
 Post subject: Re: HQL how to express complex join with two paths.
PostPosted: Thu Mar 24, 2011 8:53 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
The equivalent to the keyword "on" in HQL is "with"!
But there are many restrictions :

http://opensource.atlassian.com/project ... e/HHH-1673


Top
 Profile  
 
 Post subject: Re: HQL how to express complex join with two paths.
PostPosted: Thu Mar 24, 2011 10:55 am 
Newbie

Joined: Wed Mar 23, 2011 5:20 pm
Posts: 3
Thanks for the answer and the link to the issue. This is my first hibernate project with some serious queries and I'm forced to go to native SQL. I might get around with a patched version, but I'm not that trained to get it done is reasonable time. Have people posted hibernate distribution with including this fix?

Thanks,

Erik


Top
 Profile  
 
 Post subject: Re: HQL how to express complex join with two paths.
PostPosted: Thu Mar 24, 2011 10:59 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
I'm actually working on a patch for this point that will remove some of the restrictions (but not all of them!)
I will post it once it's done.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.