-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping a roll-up collection
PostPosted: Tue Nov 27, 2007 11:55 pm 
Newbie

Joined: Tue Nov 27, 2007 11:41 pm
Posts: 2
Hibernate version: 3.4.2sp1

Name and version of the database you are using: Postgresql 8.2

I'm running into a mental brick wall trying to work around a problem in an existing database.

I have a main table ("Main"), and several other child tables ("ChildA", "ChildB", and so on).

I also have another table, "Info", that has an <any> relation to the "Main", and several of the "ChildX" tables.

I have in those "Main" and "ChildX" tables a <set> to create a collection of the associated "Info" rows. Works great.

However my headache starts when I want to have a <set> (or other collection type, I'm not tied to <set>) in "Main" which is a collection of the "Info" rows that are related to both "Main" and the "ChildX" rows related to "Main".

In other words if "Info" has 2 rows, 1 related to "Main" id "MAIN001", and 1 related to "CLDA001", with the "ChildA" row "CLDA001" related to "MAIN001", I want a collection in "Main" that would show both "Info" rows.

Another way to think of it is as a roll-up.

Any ideas?

The one I was thinking about most was adding a property to the "Info" mapping to hold the Id of the "Main" record that was related to it, but when doing one-to-many relations it actually has to be a column, not a property. :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 07, 2007 2:59 am 
Newbie

Joined: Tue Nov 27, 2007 11:41 pm
Posts: 2
I draw a bit of a diagram to help show what I'm looking to try to do.

Code:
Basic Parent/Child Structure - Note multiple children of the parent...

                           +--------+
                           |  Main  |
                           +--------+
                           | Id <PK>|
                           | ...    |
                           +----+---+
               +---->-----------+------------<---+     
               ^                ^                ^     
        +------+-----+    +-----+------+   +-----+------+
        |   Child1   |    |   Child2   |   |   ChildN   |
        +------------+    +------------+   +------------+
        | Id <PK>    |    | Id <PK>    |   | Id <PK>    |
        | MainId <FK>|    | MainId <FK>|   | MainId <FK>|
        | ...        |    | ...        |   | ...        |
        +------------+    +------------+   +------------+
       
Now throw the wrench in:

+---------------+
|     Info      |
+---------------+
| Id <PK>       |
| RelatedId <*> |
| ...           |
+---------------+

RelatedId is an <any> mapping to the Id of any of the "Child" objects, OR the Main object itself.


Any thoughts?


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