AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Frage zu Hibernate many-to-many

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Language (German)
View previous topic :: View next topic  
Author Message
Michael Plate
Guest





PostPosted: Tue May 08, 2007 9:44 pm    Post subject: Frage zu Hibernate many-to-many Reply with quote



Hallo Leute!

ich habe drei DB-Tabellen, wobei die ersten beiden Stammdaten enthalten ist
und die letzte als Mapping-Tabelle für beide Stammdaten-Tabellen steht.

CREATE TABLE IF NOT EXISTS MASTERDATA_NO1
(
id bigint not null,
description varchar(255) not null,
primary key (id)
);

CREATE TABLE IF NOT EXISTS MASTERDATA_NO2
(
id bigint not null,
description varchar(255) not null,
primary key (id)
);

CREATE TABLE IF NOT EXISTS MAPPING_MD1_MD2
(
FK_MD1_ID bigint not null,
FK_MD2_ID bigint not null,
primary key (FK_MD1_ID, FK_MD2_ID)
);

Meine Mapping-Datei zu Hibernate sieht folgt aus:
.....
<class name="Masterdata1" table="masterdata_no1" >

<id name="id" column="id">
<generator class="increment"/>
</id>

<property name="description" column="description" />

<set name="md2" table="mapping_md1_md2">
<key column="FK_MD1_ID"/>
<many-to-many class="Masterdata2" column="FK_MD2_ID" />
</set>

</class>
...

Meine Java-Klassen sehen so ...

package at.plate.michael.hibernate.valueobject;

import java.util.HashSet;
import java.util.Set;

public class Masterdata1 {
//properties
private int id;
private String description;
private Set<Masterdata2> md2 = new HashSet<Masterdata2>();

//getter and setter for properties
public String getDescription() { return description; }
public int getId() { return id; }
public void setDescription(String description) { this.description =
description; }
public void setId(int id) { this.id = id; }
public Set<Masterdata2> getMd2() { return md2; }
public void setMd2(Set<Masterdata2> md2) { this.md2 = md2; }
}

.... und so ...

package at.plate.michael.hibernate.valueobject;

public class Masterdata2 {
//properties
private int id;
private String description;

//getter and setter for properties
public String getDescription() { return description; }
public int getId() { return id; }
public void setDescription(String description) { this.description =
description; }
public void setId(int id) { this.id = id; }
}

.... aus.


Bis jetzt läuft das ganze System perfekt. Sprich, ich bekomme Masterdata1
Objekte mit Sets an Masterdata2 Objekten.



Ich habe die Mapping-Tabelle um eine weitere Spalte erweitert und möchte den
Wert, der darin steht, zusätzlich an Masterdata2 mitgeben.

Jetzt möchte ich gerne wissen, wie ich dies in der Mapping-Datei von
Hibernate eintragen muss?

Vielen Dank im Voraus.
Michael Plate
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Language (German) All times are GMT
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.