Bonjour/Bonsoir,
Je travail présentement sur un projet scolaire, j'ai pris la décision d'utiliser Hibernate pour la persistance de mes donnée.
Voila, J'ai un problème avec les mapping <set> Dans la classe Enfant, j'ai un set de Parent. Quand je fini l'inscription de l'objet enfant, l'insertion se fait bien pour la table enfant mais rien pour la table parent (ni pour les 2 autres <set> dans la classe Enfant)
Merci d'avance aux gens qui voudrons bien me donner un coup de main !
Je joins à ce message les classes, fichiers mapping impliquer et le log..
Classe Enfant
Classe Parent
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 package Model; import java.sql.Date; import java.util.HashSet; import java.util.Set; public class Enfant implements java.io.Serializable { private String prenom; private String nomFamille; private Date dateNaissance; private Date dateInsctiption; private Set enfantAllergies = new HashSet(); private Set enfantPersonneauthorisees = new HashSet(); private char sexe; private String commentaire; private int iD; private Garderie garderie; private Set sibling = new HashSet(); private Set parent = new HashSet(); private Adresse adresse; public Enfant() { } public Adresse getAdresse() { return adresse; } public void setAdresse(Adresse adresse) { this.adresse = adresse; } public Set getEnfantAllergies() { return enfantAllergies; } public void setEnfantAllergies(Set enfantAllergies) { this.enfantAllergies = enfantAllergies; } public Set getEnfantPersonneauthorisees() { return enfantPersonneauthorisees; } public void setEnfantPersonneauthorisees(Set enfantPersonneauthorisees) { this.enfantPersonneauthorisees = enfantPersonneauthorisees; } public Set getParent() { return parent; } public void setParent(Set parent) { this.parent = parent; } public Set getSibling() { return sibling; } public void setSibling(Set sibling) { this.sibling = sibling; } public String getCommentaire() { return commentaire; } public void setCommentaire(String commentaire) { this.commentaire = commentaire; } public Date getDateInsctiption() { return dateInsctiption; } public void setDateInsctiption(Date dateInsctiption) { this.dateInsctiption = dateInsctiption; } public Date getDateNaissance() { return dateNaissance; } public void setDateNaissance(Date dateNaissance) { this.dateNaissance = dateNaissance; } public Garderie getGarderie() { return garderie; } public void setGarderie(Garderie garderie) { this.garderie = garderie; } public int getiD() { return iD; } public void setiD(int iD) { this.iD = iD; } public String getNomFamille() { return nomFamille; } public void setNomFamille(String nomFamille) { this.nomFamille = nomFamille; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public char getSexe() { return sexe; } public void setSexe(char sexe) { this.sexe = sexe; } }
Classe EnfantAllergie
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 package Model; import java.util.ArrayList; public class Parent implements java.io.Serializable { private String prenom; private String nomFamille; private String telephoneMaison; private String telephoneBureau; private String telephoneCell; private String courriel; private String nas; private String dateNaissance; private String type; private String commentaire; private String nomUsager; private String motPasse; private int iD; private Enfant enfant; // private ArrayList<Compte> compte = new ArrayList<Compte>(); private Adresse adresse; public Parent() { } public Adresse getAdresse() { return adresse; } public void setAdresse(Adresse adresse) { this.adresse = adresse; } public String getCommentaire() { return commentaire; } public void setCommentaire(String commentaire) { this.commentaire = commentaire; } // public ArrayList<Compte> getCompte() { // return compte; // } // // public void setCompte(ArrayList<Compte> compte) { // this.compte = compte; // } public String getCourriel() { return courriel; } public void setCourriel(String courriel) { this.courriel = courriel; } public String getDateNaissance() { return dateNaissance; } public void setDateNaissance(String dateNaissance) { this.dateNaissance = dateNaissance; } public Enfant getEnfant() { return enfant; } public void setEnfant(Enfant enfant) { this.enfant = enfant; } public int getiD() { return iD; } public void setiD(int iD) { this.iD = iD; } public String getMotPasse() { return motPasse; } public void setMotPasse(String motPasse) { this.motPasse = motPasse; } public String getNas() { return nas; } public void setNas(String nas) { this.nas = nas; } public String getNomFamille() { return nomFamille; } public void setNomFamille(String nomFamille) { this.nomFamille = nomFamille; } public String getNomUsager() { return nomUsager; } public void setNomUsager(String nomUsager) { this.nomUsager = nomUsager; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public String getTelephoneBureau() { return telephoneBureau; } public void setTelephoneBureau(String telephoneBureau) { this.telephoneBureau = telephoneBureau; } public String getTelephoneCell() { return telephoneCell; } public void setTelephoneCell(String telephoneCell) { this.telephoneCell = telephoneCell; } public String getTelephoneMaison() { return telephoneMaison; } public void setTelephoneMaison(String telephoneMaison) { this.telephoneMaison = telephoneMaison; } public String getType() { return type; } public void setType(String type) { this.type = type; } }
Classe EnfantPersonneauthorisee
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 package Model; // Generated 2011-05-04 19:53:39 by Hibernate Tools 3.2.1.GA /** * EnfantAllergie generated by hbm2java */ public class EnfantAllergie implements java.io.Serializable { private int iD; private Enfant enfant; private String allergie; public EnfantAllergie(Enfant enfant, String allergie) { this.enfant = enfant; this.allergie = allergie; } public EnfantAllergie() { } public int getiD() { return iD; } public void setiD(int iD) { this.iD = iD; } public Enfant getEnfant() { return this.enfant; } public void setEnfant(Enfant enfant) { this.enfant = enfant; } public String getAllergie() { return this.allergie; } public void setAllergie(String allergie) { this.allergie = allergie; } }
Fichier Mapping Enfant
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 package Model; // Generated 2011-05-04 19:53:39 by Hibernate Tools 3.2.1.GA /** * EnfantPersonneauthorisee generated by hbm2java */ public class EnfantPersonneauthorisee implements java.io.Serializable { private int iD; private Enfant enfant; private String personneAuthorisee; public EnfantPersonneauthorisee() { } public EnfantPersonneauthorisee(Enfant enfant, String personneAuthorisee) { this.enfant = enfant; this.personneAuthorisee = personneAuthorisee; } public int getiD() { return iD; } public void setiD(int iD) { this.iD = iD; } public Enfant getEnfant() { return this.enfant; } public void setEnfant(Enfant enfant) { this.enfant = enfant; } public String getPersonneAuthorisee() { return this.personneAuthorisee; } public void setPersonneAuthorisee(String personneAuthorisee) { this.personneAuthorisee = personneAuthorisee; } }
Fichier Mapping Parent
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class dynamic-insert="false" dynamic-update="false" mutable="true" name="Model.Enfant" optimistic-lock="version" polymorphism="implicit" select-before-update="false"> <id column="enfantID" name="iD"> <generator class="increment"/> </id> <property name="prenom"/> <property name="nomFamille"/> <property name="dateNaissance"/> <property name="dateInsctiption"/> <property name="sexe"/> <property name="commentaire"/> <many-to-one cascade="all" column="adesseID" name="adresse" not-null="false"/> <many-to-one cascade="all" column="garderieID" name="garderie" not-null="false"/> <set inverse="true" name="enfantPersonneauthorisees"> <key> <column name="enfantID" not-null="true"/> </key> <one-to-many class="Model.EnfantPersonneauthorisee"/> </set> <set inverse="true" name="enfantAllergies"> <key> <column name="enfantID" not-null="true"/> </key> <one-to-many class="Model.EnfantAllergie"/> </set> <set name="parent" inverse="true"> <key> <column name="enfantID" not-null="true" /> </key> <one-to-many class="Model.Parent" /> </set> </class> </hibernate-mapping>
Fichier Mapping EnfantPersonneauthorisee
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class dynamic-insert="false" dynamic-update="false" mutable="true" name="Model.Parent" optimistic-lock="version" polymorphism="implicit" select-before-update="false"> <id column="parentID" name="iD"> <generator class="increment"/> </id> <property name="prenom"/> <property name="nomFamille"/> <property name="telephoneMaison"/> <property name="telephoneBureau"/> <property name="telephoneCell"/> <property name="courriel"/> <property name="nas"/> <property name="dateNaissance"/> <property name="type"/> <property name="commentaire"/> <property name="nomUsager"/> <property name="motPasse"/> <many-to-one cascade="all" column="enfantID" name="enfant" not-null="false"/> <many-to-one cascade="all" column="adresseID" name="adresse" not-null="false"/> </class> </hibernate-mapping>
Fichier Mapping EnfantAllergie
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 2011-05-04 19:53:44 by Hibernate Tools 3.2.1.GA --> <hibernate-mapping> <class catalog="gsdg" name="Model.EnfantPersonneauthorisee" table="enfant_personneauthorisee"> <id column="enfantPersonneauthoriseeID" name="iD"> <generator class="increment"/> </id> <many-to-one class="Model.Enfant" fetch="select" insert="false" name="enfant" update="false"> <column name="EnfantID" not-null="true"/> </many-to-one> <property name="personneAuthorisee" type="string"> <column name="PersonneAuthorisee"/> </property> </class> </hibernate-mapping>
Mon Fichier de configuration Hibernate
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 2011-05-04 19:53:44 by Hibernate Tools 3.2.1.GA --> <hibernate-mapping> <class catalog="gsdg" name="Model.EnfantAllergie" table="enfant_allergie"> <id column="enfantAllergiID" name="iD"> <generator class="increment"/> </id> <many-to-one class="Model.Enfant" fetch="select" insert="false" name="enfant" update="false"> <column name="enfantID" not-null="true"/> </many-to-one> <property name="allergie" type="string"> <column name="Allergie"/> </property> </class> </hibernate-mapping>
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 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/gsdga</property> <property name="hibernate.connection.username">gsdg_app</property> <property name="hibernate.connection.password">123456</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.show_sql">true</property> <mapping resource="Model/Adresse.hbm.xml"/> <mapping resource="Model/Garderie.hbm.xml"/> <mapping resource="Model/Gestionnaire.hbm.xml"/> <mapping resource="Model/Enfant.hbm.xml"/> <mapping resource="Model/EnfantAllergie.hbm.xml"/> <mapping resource="Model/EnfantPersonneauthorisee.hbm.xml"/> <mapping resource="Model/Parent.hbm.xml"/> </session-factory> </hibernate-configuration>
Methode dans la quelle je fait le "save"
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 public static boolean saveEnfant(Enfant e) { Session session = HibernateUtil.currentSession(); Transaction tx = session.beginTransaction(); try { session.saveOrUpdate(e); tx.commit(); return true; } catch (Exception ex) { return false; } finally { HibernateUtil.closeSession(); } }
Partager