-->
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.  [ 1 post ] 
Author Message
 Post subject: "Flatten" joined collections to query on multiple
PostPosted: Fri Sep 16, 2005 3:00 pm 
Beginner
Beginner

Joined: Wed Jul 21, 2004 6:50 pm
Posts: 27
Hi,

We have a model that is basically A which has collection of B, each of which has a collection of C.

We need to query for the objects where the value of B.value is multiple values, and c.value is also multiple values. Thus we need to "flatten" out the hierarchy so we can select on multiple columns. However, this is resulting in humungous queries, and I'm trying to figure out a better way.

As an example, say we have an object A with a collection of the following objects:

- B1.value = m
B1.setC:
C1.value = 1
C2.value = 2

- B2.value = m
B2.setC:
C3.value = 1
C3.value = 2
C4.value = 5

- B3.value = n
B3.setC:
C5.value = 4
C6.value = 6

Now, I need to find all A objects where B.value = m and C.value = 1 and C.value =2.

Not too bad, you say, as we can join against C twice ie A join A.B as b1 join b1.C as c1 join b1.C as c2 where b1.value="m" and c1.value=1 and c2.value=2

The trouble is, we need to be able to search for up to 7 conditions which all have to be true (B.value and C.value can have any number of values). This means that we have to join 8 times, and then have a huge list of where conditions. To get some kind of performance, we have to make sure duplicates are not created by adding WHERE clauses to get rid of them ie WHERE c1.value <> c2.value AND c1.value <> c3.value AND c2.value <> c3.value. You can imagine how many of those there are for 8 joins!

So, I'm thinking there MUST be a better way? Please help!

cheers,

David


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

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.