-->
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: Frage zum Umstieg OJB->Hibernate und Composite-Id
PostPosted: Tue Jul 11, 2006 4:35 am 
Newbie

Joined: Tue Jul 11, 2006 4:00 am
Posts: 1
Hallo,

nachdem ich seit längerem OJB einsetze, bin ich momentan am Ausprobieren von Hibernate. Nun habe ich jedoch eine bestehende Datenbank, bei der viele Primärschlüssel aus mehr als einer Spalte bestehen. Leider klappt es damit nicht so richtig und die Doku gibt zum Thema zusammengesetzte Primärschlüssel nicht so viel her (zumindest nicht für Hibernate-Anfänger). Es scheitert schon am Mapping-File.

Folgendes soll passieren: Test2 hat als PK neben der Mandant-Nr noch die Y-Nummer aus Test1, die dort aber nicht im PK ist. Ich möchte nun eine Java Referenz haben, über die ich von Test1 nach Test2 über die RI 'navigieren' kann.
Datenbank ist DB2 am Host(390).
Ich bin für Hinweise dankbar.

[b]Hibernate version:[/b]
3.1

[b]Mapping documents:[/b]
<hibernate-mapping>
<class name="Test1" table="LSVERFT.TEST1" optimistic-lock="version">
<composite-id>
<key-property name="mandantNr" column="MANDANT_NR" access="field" type="short"/>
<key-property name="xNummer" column="X_NUMMER" access="field" type="integer"/>
</composite-id>
<version name="objektVersion" column="OBJEKT_VERSION" access="field" type="integer"/>
<property name="status" column="STATUS" access="field" type="short"/>
<property name="yNummer" column="Y_NUMMER" access="field" type="short" />

<many-to-one name="zuTest2" class="Test2">
<column name="MANDANT_NR"/>
<column name="Y_NUMMER"/>
</many-to-one>
</class>

<class name="Test2" table="LSVERFT.TEST2" optimistic-lock="version">
<composite-id>
<key-property name="mandantNr" column="MANDANT_NR" access="field" type="short"/>
<key-property name="yNummer" column="Y_NUMMER" access="field" type="short"/>
</composite-id>
<version name="objektVersion" column="OBJEKT_VERSION" access="field" type="integer"/>
<property name="yName" column="Y_NAME" access="field" type="string"/>
<property name="status" column="STATUS" access="field" type="short"/>
</class>
</hibernate-mapping>

---------------------------------------------------
Falls OJB-Experten unter uns sind, da sieht das Mapping folgendermaßen aus:
---------------------------------------------------

<descriptor-repository version="1.0" isolation-level="read-uncommitted">
<class-descriptor class="Test1" table="LSVERFT.TEST1">
<field-descriptor id="1" name="mandantNr" column="MANDANT_NR" jdbc-type="SMALLINT" primarykey="true" access="readwrite" autoincrement="false"/>
<field-descriptor id="2" name="xNummer" column="X_NUMMER" jdbc-type="INTEGER" primarykey="true" access="readwrite" autoincrement="false"/>
<field-descriptor id="3" name="objektVersion" column="OBJEKT_VERSION" jdbc-type="INTEGER" primarykey="false" access="readwrite" autoincrement="true" locking="true"/>
<field-descriptor id="4" name="status" column="STATUS" jdbc-type="SMALLINT" primarykey="false" access="readwrite" autoincrement="false"/>
<field-descriptor id="5" name="yNummer" column="Y_NUMMER" jdbc-type="SMALLINT" primarykey="false" access="readwrite" autoincrement="false"/>

<reference-descriptor name="zuTest2" class-ref="Test2" proxy="true">
<foreignkey field-ref="mandantNr"/>
<foreignkey field-ref="yNummer"/>
</reference-descriptor>
</class-descriptor>

<class-descriptor class="Test2" table="LSVERFT.TEST2">
<field-descriptor id="1" name="mandantNr" column="MANDANT_NR" jdbc-type="SMALLINT" primarykey="true" access="readwrite" autoincrement="false"/>
<field-descriptor id="2" name="yNummer" column="Y_NUMMER" jdbc-type="SMALLINT" primarykey="true" access="readwrite" autoincrement="false"/>
<field-descriptor id="3" name="objektVersion" column="OBJEKT_VERSION" jdbc-type="INTEGER" primarykey="false" access="readwrite" autoincrement="true" locking="true"/>
<field-descriptor id="4" name="yName" column="Y_NAME" jdbc-type="CHAR" primarykey="false" access="readwrite" autoincrement="false"/>
<field-descriptor id="5" name="status" column="STATUS" jdbc-type="SMALLINT" primarykey="false" access="readwrite" autoincrement="false"/>
</class-descriptor>
</descriptor-repository>


[b]Code between sessionFactory.openSession() and session.close():[/b]

[b]Full stack trace of any exception that occurs:[/b]
org.hibernate.MappingException: Repeated column in mapping for entity: Test1 column: MANDANT_NR (should be mapped with insert="false" update="false")

[b]Name and version of the database you are using:[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]


Top
 Profile  
 
 Post subject: Frage zum Umstieg OJB->Hibernate und Composite-Id
PostPosted: Wed Jul 12, 2006 10:58 am 
Regular
Regular

Joined: Mon May 22, 2006 8:32 am
Posts: 67
Hi,

ich kann Dir die HibernateTools empfehlen. Dort kannst Du dir per Reverse engeneering die Files erstellen lassen. Das kannst Du dann als Grunlage für Deine "Forschungen" nehmen und Details per Hand ändern.

Viel Spaß,

ak


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.