Bonsoir a tous je travaille sur un projet javaFX tout en utilisant Spring data, hibernate...Mon soucis est le suivant:
j'ai deux classes Matiere et classe tout deux liés par une association du type ManyToMany donnant lieu a une classe d'association appelé matiere_classe.
Premierement, En plus des clés etrangere que recois matiere_classe j'aimerai lui ajouter un autre attribut nomé coefficient.
deuxiemement j'aimerai effectuer des requetes dans cette table d'association a partir de hibernate ou spring data mais je ne sais comment procedé puisque je n'est pas d'entité representant cette table d'association.
voici la structure de mes classes
pour la classe Matiere
classe Classe:
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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 @Entity @Table(name="matiere") public class Matiere implements Serializable { private static final long serialVersionUID = 3895067429721912194L; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private Long id_matiere; private String nom; private String niveau; private int coefficient; private int semestre; private String supervisor; @ManyToMany(fetch=FetchType.EAGER) @JoinTable(name = "matiere_classe", joinColumns = @JoinColumn(name = "id_matiere"), inverseJoinColumns = @JoinColumn(name = "id_classe")) private List<Classe> classes = new ArrayList<Classe>(); public Matiere() { super(); } public List<Classe> getClasses() { return classes; } public void setClasses(List<Classe> classes) { this.classes = classes; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getNiveau() { return niveau; } public void setNiveau(String niveau) { this.niveau = niveau; } public int getCoefficient() { return coefficient; } public void setCoefficient(int coefficient) { this.coefficient = coefficient; } public int getSemestre() { return semestre; } public void setSemestre(int semestre) { this.semestre = semestre; } public String getSupervisor() { return supervisor; } public void setSupervisor(String supervisor) { this.supervisor = supervisor; } public Long getId_matiere() { return id_matiere; } }
Voici le contenu de la table d'association. par exemple comment recuperé toutes les matieres qui ont pour id_classe 2
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
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 @Entity @Table(name = "classe") public class Classe implements Serializable { /** * */ private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id_classe; private String nom; private String niveau; private String titulaire; private String chef; private String sous_chef; private String delegue1; private String delegue2; @Transient private Long total; @OneToMany(mappedBy = "classe", fetch = FetchType.EAGER) Collection<Etudiant> etudiant; @ManyToMany(mappedBy = "classes") private Collection<Matiere> matieres = new ArrayList<Matiere>(); public Classe() { super(); } public Long getTotal() { return total; } public void setTotal(Long total) { this.total = total; } public Collection<Matiere> getMatieres() { return matieres; } public void setMatieres(Collection<Matiere> matieres) { this.matieres = matieres; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getNiveau() { return niveau; } public void setNiveau(String niveau) { this.niveau = niveau; } public String getTitulaire() { return titulaire; } public void setTitulaire(String titulaire) { this.titulaire = titulaire; } public String getChef() { return chef; } public void setChef(String chef) { this.chef = chef; } public String getSous_chef() { return sous_chef; } public void setSous_chef(String sous_chef) { this.sous_chef = sous_chef; } public String getDelegue1() { return delegue1; } public void setDelegue1(String delegue1) { this.delegue1 = delegue1; } public String getDelegue2() { return delegue2; } public void setDelegue2(String delegue2) { this.delegue2 = delegue2; } public Long getId_classe() { return id_classe; } public Collection<Etudiant> getEtudiant() { return etudiant; } public void setEtudiant(Collection<Etudiant> etudiant) { this.etudiant = etudiant; } }
Partager