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.
|