-->
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: Bi-directional mapping using <ANY>
PostPosted: Mon May 30, 2005 1:24 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
Hi,

I posted a similar question earlier, but I've had a chance to brainstorm a bit more: What I'm looking to do is a polymorphic bi-directional 1-to-n mapping. I have class A, B and C who all have 1-to-many relationships with X. A owns0 or more X's, B owns 0 or more X's, etc. I want X to link back to its parent, either A, B or C. I can do the one way mapping (A-to-X etc.) just fine, as all my primary keys are unique across the DB (i.e. there will never be a key collision between A and B). So I can simply put a mapping into A:

<set name="items">
<key column="parent_id"/>
<one-to-many class="X"/>
</set>

... and the same goes for B and c, as "parent_id" can refer to any of the three classes.

The tricky part comes in when I want to create a bi-directional association, so X can point back to its parent. Can I use <ANY> for this, and if so, what would my mapping look like?

Yes, I know the *ideal* way would be to create a superclass for A, B and C that owns X, but my model does not allow for it. My actual hierarchy is much more complex and would require multiple inheritance etc. I also want to keep query performance high by not hitting more tables than necessary.

What is the best way to accomplish this?

Thanks!

Jen


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.