-->
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: 1:n mapping on strange legacy schema
PostPosted: Fri Jan 12, 2007 10:54 am 
Newbie

Joined: Thu Jan 11, 2007 11:37 am
Posts: 2
Hi Hibernate-experts,

since some days I'm fiddling around to find a working mapping, but could not find help google, FAQ, doc, etc., so here's my cry for help:

In effect it's a simple 1:n relationship between two tables from a legacy schema, called PARENT and CHILD in this mail. I need read-only access so that a Parent class contains an ordered Collection of Child instances (List?).

The adversity hereby is the following (the schema belongs to a 3rd party product I can't influence, so don't blame me ;-)
1. The PARENT table has a compound primary key consisting of two attributes (KEY1, KEY2)
2. The two tables are connected via a column "trncode", existing in both tables as a plain vanilla attribute
3. "trncode" isn't unique in the PARENT table (what makes it not really a 1:n relationship, but because I'm only navigating read-only from PARENT, that's not important)

My current mapping looks like this:

Code:
<hibernate-mapping>
  <class table="PARENT" name="foo.Parent">
    <composite-id>
      <key-property name="key1" access="field" column="KEY1"/>
      <key-property name="key2" access="field" column="KEY2"/>
    </composite-id>
    <property name="trnCode" access="field" column="TRNCODE"/>
    <property name="parentInfo" access="field" column="PAR_INF"/>
    ...
    <map name="childs" table="CHILD">
      <key column="trncode"/>
      <map-key type="string" column="trncode"/>
      <composite-element class="foo.Child">
        <property name="childInfo" access="field" column="CHILD_INF"/>
        ...
      </composite-element>
    </map>
  </class>
</hibernate-mapping>

Executing this, I get the following error from Hibernate:

Code:
org.hibernate.MappingException: Foreign key (FK9D18367CBF36D4AA:CHILD [trncode])) must have same number of columns as the referenced primary key (PARENT [KEY1,KEY2])


I had similar results when I was mapping CHILD as Entity (instead of component).

My current workaround is that I don't even map the relation at all, but query it "by hand" in the code and insert it into a transient child-List, but there has to be a better way...

Many thanks for any help!

zott

PS: Hibernate 3.1, Oracle 9


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.