-->
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 on join table with shared primary key attributes
PostPosted: Fri May 01, 2009 5:01 pm 
Beginner
Beginner

Joined: Mon Jun 19, 2006 4:10 pm
Posts: 27
If Parent has primary key composed of a and b, and Child has primary key composed of a and c, how does one map this on a join table? looking at the documentation I tried what was suggested for many-to-many, but it doesn't work

Code:
<list name="childs" table="ParentChild">
            <key>
                <column name="A" />
                <column name="B" />
            </key>
            <list-index column="idx" base="0"/>
            <many-to-many class="Child"
                          unique="true" >
                <formula>A</formula>
                <column name="C" />
            </many-to-many>
        </list>


this fails with a sql exception about invalid column index when inserting the join table row, after inserting the child. i think what is happening is because I am joining 2 tables with 2-tuple primary keys, it is expecting 4 columns to be in the join table (+1 for idx). But because one is shared, there should only be 3 (+1 for index). The sql that hibernate generates looks good "insert into ParentChild (A, B, idx, C) values (?, ?, ?, ?)" but I get the mentioned sql exception.

When i step thru with the debugger, I see A getting set on the prepared statement, then B, then A again, then C, at which point it dies (because it tries to set the 5th parameter on the PS, when there are only 4, hence the invalid column...)


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.