-->
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: One to many from mulitple sources
PostPosted: Wed May 16, 2007 2:53 pm 
Newbie

Joined: Wed May 16, 2007 1:35 pm
Posts: 4
Hibernate version: 3.2
Database: Oracle 10g

Hi all,

The standard one-to-many mapping assumes two classes, Foo and Bar which are related to each other as follows:
Code:
Set Foo.getBars() // of Bar instances

The mapping would be
Code:
<class name="Foo" table="foo">
  ...
  <set role="bars" table="bar">
    <key column="foo_id"/>
    <one-to-many class="Bar" not-found="ignore|exception"/>
  </set>
</class>

I use the <set> collection for the purpose of this example, it could be a different one.

Bar's table requires an extra column, which holds the FK to Foo. This allows Foo to be assigned a collection of Bars based on the value of the foo_id column in Bar.
THE PROBLEM arises when I want multiple classes to have one-to-many mappings to Bar. Let's say I want Foo1, Foo2, Foo3... etc. to all have a one-to-many mapping to Baz. So I would have the following relations:
Code:
Set Foo1.getBars()
Set Foo2.getBars()
...

Now the FK column in Baz needs an additional FK_TYPE column to determine which FooX class it references.

I couldn't find discussions of this situation (or how to map it) in literature, documentation, or int he forums.

Is this possible?
How would I structure my mappings to do this?

Thanks!


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.