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.  [ 5 posts ] 
Author Message
 Post subject: collection query - how to
PostPosted: Wed Apr 14, 2004 11:32 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
I have 3 tables

A(id, a1,a2)
B(id, fk_a_id, b1,b2)
C(id, fk_b_id, c1,c2)

related as

A (one to many) B (one to many ) C using Set and bidirectionally true

I have a use case like this:

Get me all A objects where B.b1 = "x" or C.c2 = "x"

I can implement this in two steps :
    a ) if B.b1 defined,
    then query on A , where B.b1 = "x" by joining A and B

    b ) if B.b1 is not defined and C.c3 is defined
    then query on B C.c2 = "x" by joining B and C , then
    for each of these B's, get the A's



Are there any any other/elegant way of implementing this ?

Thanks
Shishir


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 3:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well does
Code:
from A a join B b join C c where b.b1 = 'X' or c.c2 = 'x'
not do what you want?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 11:28 am 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Michael,

This works fine as long as I limit myself to getting only A with lazy loading true and outer join = false at global level. However, after getting A (session is now closed), I would like to then get to related B and C (based on my criteria). How do I do that ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can reattatch A using session.lock and use a collection filter probably


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 1:49 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
That is what I was trying to avoid :) , and kind of was looking for a one shot sql /method to load A, related B and related C but since this feature is not supported (colection of collection), I guess there's no other work around, other than what you specified.

Thanks
Shishir


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