-->
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 of extents question
PostPosted: Tue Sep 02, 2003 9:08 pm 
Newbie

Joined: Tue Sep 02, 2003 8:57 pm
Posts: 5
So I have a rather complex mapping I'm trying to accomplish. I have an object ("message") that can contain multiple children ("attributes") in a one-to-many relationship. The children represent an extent or system of subclasses. So there's BaseAttribute, FooAttribute, BarAttribute, etc. There can be zero to many of each kind of attribute associated with the message, but at most one of any instance. This hierarchy of attributes is meant to be extensible, so I want to be able to add new attributes at a later date. Right now the hierarchy consists of ~20 kinds of attribute.

I've got this somewhat modeled using joined-subclass and one-to-many. It creates an outer-join from hell (as I expected). I chose the joined-subclass since it seems to leave open the possiblity of adding more attributes in the future by simply adding more tables.

Now I'm trying to figure out how to query. Naturally I want to query for messages based on the various attributes. The FAQ question "How do a write a query that returns objects based upon a WHERE clause condition applied to their collection elements?" is close to what I want, but it doesn't deal with the fact that my collection is polymorphic.

So I guess I have two questions: 1. Like the FAQ question cited, but for polymorphic collection elements. 2. Any better ideas on how to do my mapping?

Thanks much


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 6:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Why should polymorphism make any difference at all to the query? I don't understand.


Top
 Profile  
 
 Post subject: Why polymorphism matters
PostPosted: Wed Sep 03, 2003 12:07 pm 
Newbie

Joined: Tue Sep 02, 2003 8:57 pm
Posts: 5
Sorry, I guess I wasn't complete in my exlanation.

Ok, so consider BaseAttribute has some property named "foo", and BarAttribute extends BaseAttribute. Now I want to retrieve all messages with attributes of type BarAttribute where foo = 7. How do I specify this in the where clause? I can't seem to refer to the class in the where clause (BarAttribute.foo = 7), and specifying the barattribute table won't work because the foo column is the the baseattribute table. If I specify the baseattribute table, then I'm ignoring the criteria that it be a BarAttribute with this value... see what I mean?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 9:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Oh, you want to do a typecast?


What you should do in these kinds of cases is "turn the query backwards". Make the association bidirectional and start from the other end of the association.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 10:04 pm 
Newbie

Joined: Tue Sep 02, 2003 8:57 pm
Posts: 5
Ok, I've got the bidi thing working, but I'm pretty confused about how to turn the query backwards. I want to find all parents with various kinds of children. So I want to say, find me zoos join animals where (elephant)animal.snouts > 2ft and (lion)animal.mane = yellow.

I could imagine "turning it around" to mean search for lion manes of yellow and then using getParent() to find the corresponding zoos. I'm not sure, however, how this is supposed to work for multiple criteria.

In any event, the SQL hibernate needs to generate to do the casting isn't bad -- it just needs specify the discriminator. So "(lion)animal.mane = yellow" would become "discriminator=lion and mane=yellow".

(I've reworked my code to use a simpler mapping than the one I alluded to earlier. Now I've got a single class-hierarchy table, and a much-simplified class hierarchy too.... but still having trouble...)

Thanks again


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.