Bonjour,

Je cherche à modéliser une association ternaire, bidirectionnelle, avec des annotations JPA/Hibernate.

Il y a une relation "ManyToMany" entre Perso et Manif, avec des informations portées par la relation :
  • Perso : idPerso (PK)
  • Manif : idManif (PK)
  • PersoManif : idPerso (PK), idManif (PK), détail1, détail2


Voici le début de mon code Java :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
@Entity @Table public class Perso implements Serializable {
  @Id public Integer idPerso;
}
 
@Entity @Table public class Manif implements Serializable {
  @Id public Integer idManif;
}
 
@Embeddable public class Détails implements Serializable {
  public String détail1;
  public String détail2;
}
(la classe Détails sera réutilisée)

A partir de là, j'entrevois deux solutions...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
@Entity @Table public class Perso implements Serializable {
  @Id public Integer idPerso;
  public Map<Manif, Détails> manifs;
}
 
@Entity @Table public class Manif implements Serializable {
  @Id public Integer idManif;
  public Map<Perso, Détails> persos;
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class PersoManif implements Serializable {
  public Perso perso;
  public Manif manif;
  public Détails détails;
}
 
@Entity @Table public class Perso implements Serializable {
  @Id public Integer idPerso;
  public Collection<PersoManif> manifs;
}
 
@Entity @Table public class Manif implements Serializable {
  @Id public Integer idManif;
  public Collection<PersoManif> persos;
}
Ce doit être un cas classique, et pourtant...
Merci de votre aide.