-->
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: Odd Many to Many relationship
PostPosted: Thu Jun 24, 2004 1:22 pm 
Newbie

Joined: Thu Jun 24, 2004 12:59 pm
Posts: 4
Using v. 2.1.4

Trying to build a map for an odd data model that is out of my control. The scenario is as follows.

Child table can be used in multiple Parent tables. Child table has a composite key of two columns. One element of this composite key is referenced in the parent table. Logically this is one parent to many children however this is not enforced in the datamodel so technically this is a many to many relation ship without a junction table.

Below is the mapping in one of the parents:


Code:
<set
            name="child"
            lazy="false"
            inverse="false"
            cascade="all-delete-orphan"
            sort="unsorted"
        >

              <many-to-many
                  class="com.bleh.Child"
                  column="CHILD_ID"
                  outer-join="auto"
               />

        </set>


The mapping for child is as follows:

Code:
<hibernate-mapping>
    <class
        name="com.bleh.Child"
        table="CHILD"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <composite-id
            name="primaryKey"
            class="com.bleh.ChildPK"
        >
                     <key-property
                        name="childId"
                        type="long"
                        column="CHILD_ID"
                />

                     <key-property
                        name="otherChilidId"
                        type="int"
                        column="OTHER_CHILD_ID"
                />

        </composite-id>

       ...other properties 
    </class>

</hibernate-mapping>


When this runs I get the following exception:

Foreign key (child [CHILD_ID])) must have same number of columns as the reference primary key (CHILD [CHILD_ID, OTHER_CHILD_ID]).

I would like to know if this is even possible. There are approximately 20 parent classes and there are about 10 properties on the child so it would be nice to avoid having to write so many composite components as referenced here http://www.xylax.net/hibernate/composite.html

Thanks for any help or pointers to my obvious newbie oversights.


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.