Bonjour,
D'après vos conseils, j'essaye de réaliser le mapping me permettant d'atteindre ma table "Competencev2" de ma base de données. Pour vous aider j'ai réaliser un schéma :
http://www.casimages.com/img.php?i=1...2162614809.png
J'ai également créé la classe NoteCompetence.java :
Ma classe Technicien.java :
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 /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package domaine; /** * * @author NHDF1037 */ public class NoteCompetence { private Technicien technicienConcerne; private Competencev2 competenceConcerne; private String note; /** * Creates a new instance of NoteCompetence */ public NoteCompetence() { } /** * @return the technicienConcerne */ public Technicien getTechnicienConcerne() { return technicienConcerne; } /** * @param technicienConcerne the technicienConcerne to set */ public void setTechnicienConcerne(Technicien technicienConcerne) { this.technicienConcerne = technicienConcerne; } /** * @return the competenceConcerne */ public Competencev2 getCompetenceConcerne() { return competenceConcerne; } /** * @param competenceConcerne the competenceConcerne to set */ public void setCompetenceConcerne(Competencev2 competenceConcerne) { this.competenceConcerne = competenceConcerne; } /** * @return the note */ public String getNote() { return note; } /** * @param note the note to set */ public void setNote(String note) { this.note = note; } }
Ma classe Technique.java :
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174 package domaine; // Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA import java.util.HashSet; import java.util.List; import java.util.Set; import javax.persistence.*; @Entity @Table(name="technicien", catalog="comptechv2", uniqueConstraints= { @UniqueConstraint(columnNames="nom"), @UniqueConstraint(columnNames="prenom"), @UniqueConstraint(columnNames="num_gsm"), @UniqueConstraint(columnNames="id_reponsable"), @UniqueConstraint(columnNames="id_loc"), @UniqueConstraint(columnNames="mobilite"), @UniqueConstraint(columnNames="date_naissance"), @UniqueConstraint(columnNames="id_domaine"), @UniqueConstraint(columnNames="depart"), }) /** * Technicien generated by hbm2java */ public class Technicien implements java.io.Serializable { private String idFt; private Domaine domaine; private Localisation localisation; private Responsable responsable; private String nom; private String prenom; private String numGsm; private String mobilite; private String dateNaissance; private String depart; private Set<Technique> techniques = new HashSet<Technique>(0); private List<NoteCompetence> notes; public Technicien() { } public Technicien(String idFt, Domaine domaine, Localisation localisation, Responsable responsable, String nom, String prenom, String numGsm, String mobilite, String dateNaissance, String depart) { this.idFt = idFt; this.domaine = domaine; this.localisation = localisation; this.responsable = responsable; this.nom = nom; this.prenom = prenom; this.numGsm = numGsm; this.mobilite = mobilite; this.dateNaissance = dateNaissance; this.depart = depart; } @Id @GeneratedValue(strategy= GenerationType.IDENTITY) @Column(name="id_ft", unique= true, nullable= false) public String getIdFt() { return this.idFt; } public void setIdFt(String idFt) { this.idFt = idFt; } @Column(name="id_domaine",unique= true, nullable=false, length= 11) public Domaine getDomaine() { return this.domaine; } public void setDomaine(Domaine domaine) { this.domaine = domaine; } @Column(name="id_loc",unique= true, nullable=false, length= 11) public Localisation getLocalisation() { return this.localisation; } public void setLocalisation(Localisation localisation) { this.localisation = localisation; } @Column(name="id_reponsable",unique= true, nullable=false, length= 11) public Responsable getResponsable() { return this.responsable; } public void setResponsable(Responsable responsable) { this.responsable = responsable; } @Column(name="nom",unique=true, nullable=false) public String getNom() { return this.nom; } public void setNom(String nom) { this.nom = nom; } @Column(name="prenom",unique= true, nullable=false) public String getPrenom() { return this.prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } @Column(name="num_gsm",unique= true, nullable=false, length= 50) public String getNumGsm() { return this.numGsm; } public void setNumGsm(String numGsm) { this.numGsm = numGsm; } @Column(name="mobilite",unique= true, nullable=false) public String getMobilite() { return this.mobilite; } public void setMobilite(String mobilite) { this.mobilite = mobilite; } @Column(name="date_naissance",unique= true, nullable=false, length= 50) public String getDateNaissance() { return this.dateNaissance; } public void setDateNaissance(String dateNaissance) { this.dateNaissance = dateNaissance; } @Column(name="depart",unique= true, nullable=false, length= 50) public String getDepart() { return this.depart; } public void setDepart(String depart) { this.depart = depart; } @ManyToMany(fetch= FetchType.LAZY, cascade= CascadeType.ALL) @JoinTable(name="competencev2", catalog= "comptechv2", joinColumns= { @JoinColumn(name= "id_technicien", nullable= false, updatable= false)}, inverseJoinColumns= {@JoinColumn(name= "id_technique", nullable= false, updatable= false)}) /** * @return the techniques */ public Set<Technique> getTechniques() { return techniques; } /** * @param techniques the techniques to set */ public void setTechniques(Set<Technique> techniques) { this.techniques = techniques; } /** * @return the notes */ public List<NoteCompetence> getNotes() { return notes; } /** * @param notes the notes to set */ public void setNotes(List<NoteCompetence> notes) { this.notes = notes; } }
Ces classes fonctionnent de la manière suivant :
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 package domaine; // Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA import java.util.HashSet; import java.util.Set; import javax.persistence.*; @Entity @Table(name= "technique", catalog= "comptechv2") /** * Technique generated by hbm2java */ public class Technique implements java.io.Serializable { private Integer idTechnique; private Produit produit; private Domaine domaine; private String categorieTechnique; private String nomTechnique; private Set<Technicien> techniciens = new HashSet<Technicien>(0); public Technique() { } public Technique(Produit produit, Domaine domaine, String categorieTechnique, String nomTechnique) { this.produit = produit; this.domaine = domaine; this.categorieTechnique = categorieTechnique; this.nomTechnique = nomTechnique; } @Id @GeneratedValue(strategy= GenerationType.IDENTITY) @Column(name="id_technique", unique= true, nullable= false) public Integer getIdTechnique() { return this.idTechnique; } public void setIdTechnique(Integer idTechnique) { this.idTechnique = idTechnique; } @Column(name="code_produit", nullable=false, length= 11) public Produit getProduit() { return this.produit; } public void setProduit(Produit produit) { this.produit = produit; } @Column(name="id_domaine",unique=true, nullable=false, length= 11) public Domaine getDomaine() { return this.domaine; } public void setDomaine(Domaine domaine) { this.domaine = domaine; } @Column(name="categorie_technique", nullable=false) public String getCategorieTechnique() { return this.categorieTechnique; } public void setCategorieTechnique(String categorieTechnique) { this.categorieTechnique = categorieTechnique; } @Column(name="nom_technique",unique= true, nullable=false) public String getNomTechnique() { return this.nomTechnique; } public void setNomTechnique(String nomTechnique) { this.nomTechnique = nomTechnique; } @ManyToMany(fetch= FetchType.LAZY, mappedBy= "techniques") /** * @return the techniciens */ public Set<Technicien> getTechniciens() { return techniciens; } /** * @param techniciens the techniciens to set */ public void setTechniciens(Set<Technicien> techniciens) { this.techniciens = techniciens; } }
Un technicien dispose d'une fiche de compétence sur l'ensemble des techniques, avec une notre par technique (id_technique) allant de 0 à 4.
Mes recherches dans mon application sont donc de ce type, exemple :
"Recherchez l'ensemble des techniciens, ayant la note 3 sur l'id_Technique 110"
Sommes nous d'accord sur le Mapping que je dois mettre en place :
many-to-one entre Technicien et NoteCompetence
many-to-one entre Competence et NoteCompetence
one-to-many entre NoteCompetence et Technicien
one-to-many entre NoteCompetence et Competence
D'avance merci
Fred
Partager