Hi there.
I've got a Problem with composed keys in Hibernate.
Here is my current structure:
Code:
@Entity
@Table(name="FILIALKONTAKT")
public class FilialKontakt implements Serializable {
/**
*
*/
private static final long serialVersionUID = -3669314898011844021L;
@Id
@ManyToOne(fetch=FetchType.EAGER,cascade = CascadeType.PERSIST)
@JoinColumn(name = "FILIALID", insertable=true, updatable=true)
private Filiale myFiliale;
@Id
@ManyToOne(fetch=FetchType.EAGER,cascade = CascadeType.PERSIST)
@JoinColumn(name = "KONTAKTID", insertable=true, updatable=true)
private Kontakte myKontakt;
@Column
private Integer primaerKz;
public FilialKontakt() {
}
//nachfolgend getter und setter
Code:
@Entity
@Table(name="ADRESSLISTE")
public class Adressliste {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ADRESSLISTEID")
private Integer adresslisteid;
@Column(name="BEZEICHNUNG")
private String bezeichnung;
public Adressliste() {
}
//nachfolgend getter und setter
Now I want to make a Table wich contains the "AdresslistID", "FilialID" and the "KontaktID" as primary Key.
My Problem is, that i doesn't know, how to handle the composed keys and how to join them.
In another part I have this structure:
Table: Filiale(ID (PK), Name)
Table: Branche(ID (PK), Name)
and the "Help"-Table: Tabelle FilialBranche(FilialID(PK/FK), BrancheID(PK/FK))
And my (working) Annotations looks like this:
Code:
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinTable(name="FILIALBRANCHE", joinColumns = {
@JoinColumn(name="FILIALID") }, inverseJoinColumns = {
@JoinColumn(name="BRANCHEID") } )
private Set <Branche> myBranche = new HashSet<Branche>(0);
But this doesn't work for my first structure.
I hope you understand my Problem and I also hope, that my english is not that bad.