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: Hilfe: 1:n mapping in widrigem Legacy-Schema
PostPosted: Thu Jan 11, 2007 12:17 pm 
Newbie

Joined: Thu Jan 11, 2007 11:37 am
Posts: 2
Hallo Hibernate-Experten,

ich tüftel hier schon ein paar Tage an einem Mapping für Hibernate 3.1 und hab auch in Foren, FAQ usw. nichts gefunden, daher meine Bitte um Hilfe...

Eigentlich ist es eine ganz einfache 1:n Beziehung aus einem Legacy-Schema zweichen zwei Tabellen, die ich hier mal PARENT und CHILD nenne. Auf diese Tabellen will ich nur lesend zugreifen, die Parent-Klasse soll eine Liste mit Child-Instanzen enthalten.

Die Widrigkeiten an der Sache sind folgende (das Schema gehört zu einem Fremdprodukt auf das ich keinen Einfluss habe -> don't blame me):
1. Die PARENT-Tabelle hat einen Compound-Primary-Key aus zwei anderen Attributen (KEY1, KEY2)
2. Verknüpft wird über eine andere Spalte "trncode", die in beiden Tabellen als normale Spalte vorhanden ist
3. "trncode" ist in der Parent-Tabelle nicht unique (das spielt aber keine Rolle, da ich nur vom Parent kommend navigieren will, zudem read-only)

Mein Mapping sieht etwa so aus:

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>


Beim Ausführen bekomme ich folgenden Fehler:

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


Ähnliche Ergebnisse hatte ich auch, als ich CHILD als Entity (statt als Component) gemappt habe.

Momentan hab ich das so gelöst, dass ich die Relation gar nicht mappe sondern im Code manuell nachlade, aber das muss doch besser gehen...

Ich bin für jede Hilfe dankbar!

zott

PS: Hibernate 3.1, Oracle 9


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 10:47 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hallo,
lese mal unter dem Begriff property-ref in der Hibernate Reference.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.