I have a class that represents a DB TABLE, this table has to have a primary key that must be a composition of three foreign keys. How could I do this with Spring boot?
You can find below the code for the classes. The table in question is InfoLocal. It is the one that must have a primary key composed of (the id of the table Local, the id of the table Annee, and the id of the table CodeLocal) which are foreign keys.
[ Please note that @IdClass and @EmbeddedId annotations don't respond to my use case ]
@Entity
public class InfoLocal {
private int nombreDeLocaux;
private int capaciteUnitaire;
@ManyToOne
private Local local;
@ManyToOne
private Annee annee;
@ManyToOne
private CodeLocal codeLocal;
/* ......*/
}
@Entity
public class Local {
@Id
private int id;
private String libelleArabe;
private String libelleFrancais;
private int codePatrimoine;
@ManyToOne
private Etablissement etablissement;
@OneToMany(mappedBy = "local")
private Collection<InfoLocal> infoLocals;
/* ......*/
}
@Entity
public class CodeLocal {
@Id
private int code;
private String libelleArabe;
private String libelleFrancais;
@OneToMany(mappedBy = "codeLocal")
private Collection<InfoLocal> infoLocal;
@ManyToOne
private TypeLocal typeLocal;
/* ......*/
}
@Entity
public class Annee {
@Id
private int codeAnnee;
private String intitule;
@OneToMany(mappedBy = "annee")
private Collection<InfoLocal> infoLocal;
/* ......*/
}