-->
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: ManyToMany-relationship with Index-Column
PostPosted: Mon Aug 20, 2007 8:55 am 
Beginner
Beginner

Joined: Wed Jul 18, 2007 6:13 am
Posts: 28
Hello everybody

I have to translate the following XDoclet-code.

/**
* @hibernate.list table="PERSON_ADRESSE" cascade="none"
* access="field"
* @hibernate.collection-many-to-many column="FK_ADRESSE"
* class="XYZ"
* @hibernate.collection-key column="FK_PERSON"
* @hibernate.collection-index column="SORT_INDEX"
*/

With other words. It exists a unidirectional ManyToMany relationship to the class XYZ. Hibernate Annotations should create a new table ("PERSON_ADRESSE"), which have two foreign keys ("FK_ADRESSE" and "FK_PERSON") and a Index-Column ("SORT_INDEX")

The table "PERSON_ADRESSE" should have 3 columns ("FK_ADRESSE", "FK_PERSON " and "SORT_INDEX")

I have no problems to create the new table with the two foreign keys (look at my example at the end of the page)

But I don't know how I can create the Index-Column.

I try to solve the problem with @IndexColumn and @Index, but nothing happend.

@ManyToMany(targetEntity=XYZ.class)
@AccessType("field")
@JoinTable(name="PERSON_ADRESSE",
joinColumns=@JoinColumn(name="PERSON_FK"),
inverseJoinColumns=@JoinColumn(name="ADRESSE_FK"))
@Index(name="SORT_INDEX")
Collection<Adresse> adressen;

@ManyToMany(targetEntity=XYZ.class)
@AccessType("field")
@JoinTable(name="PERSON_ADRESSE",
joinColumns=@JoinColumn(name="PERSON_FK"),
inverseJoinColumns=@JoinColumn(name="ADRESSE_FK"))
@IndexColumn(name = "SORT_INDEX")
Collection<Adresse> adressen;

Can somebody help me?

Klasse Person

@Entity
@Table(name = "PERSON")
public class Person {

@Id
@Column(name = "PK_ID")
int id;

@Column(name = "VORNAME")
String vorname;

@Column(name = "NACHNAME")
String nachname;


@ManyToMany(targetEntity=XYZ.class)
@AccessType("field")
@JoinTable(name="PERSON_ADRESSE",
joinColumns=@JoinColumn(name="PERSON_FK"),
inverseJoinColumns=@JoinColumn(name="ADRESSE_FK"))
Collection<Adresse> adressen;

public Collection<Adresse> getAdressen() {
return adressen;
}

public void setAdressen(Collection<Adresse> adressen) {
this.adressen = adressen;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getNachname() {
return nachname;
}

public void setNachname(String nachname) {
this.nachname = nachname;
}

public String getVorname() {
return vorname;
}

public void setVorname(String vorname) {
this.vorname = vorname;
}

}

Klasse Adresse

@Entity
@Table(name = "ADRESSE")
public class Adresse {

@Id
@Column(name = "ID")
int id;

@Column(name = "STRASSE")
String strasse;

@Column(name = "HAUSNUMMER")
String hausnummer;

@Column(name = "PLZ")
int plz;

public String getHausnummer() {
return hausnummer;
}

public void setHausnummer(String hausnummer) {
this.hausnummer = hausnummer;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getPlz() {
return plz;
}

public void setPlz(int plz) {
this.plz = plz;
}

public String getStrasse() {
return strasse;
}

public void setStrasse(String strasse) {
this.strasse = strasse;
}

}


Ein ähnliches Problem habe ich übrigens bei folgendem XDoclet-Tag:

/**
* @hibernate.collection-one-to-many class="XYZ"
* @hibernate.collection-key
* @hibernate.collection-key-column name="FK_HISTORIE"
* @hibernate.collection-index column="SORT_INDEX"
*/

Aber ich denke das ähnelt dem obigen Problem.


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.