Bonjour,
dans le cadre de mon développement j'utilise Hibernate pour le mapping avec ma base. Pour résumer, j'ai une table (qui correspond à un formulaire) qui contient plusieurs clés étrangères (criticite, intervenant, ...).
Mais lorsque j'essaie d'ajouter un enregistrement dans ma table j'ai une erreur.
Du coup, je voudrais savoir d'où peut provenir le problème et est-ce que le mapping est bien fait.
Voici mon code :
Mon fichier de 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
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 SessionFactory sessionFactory = new Configuration().configure() .buildSessionFactory(); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); // Create new instance of Contact and set values in it by reading // them from form object System.out.println("Inserting Book object into database... "); T_Dem_S dem_S = new T_Dem_S(); String s_date_clo = newSigSout.getDate_clo(); // NULL String s_date_pec = newSigSout.getDate_pec(); // NULL String s_date_res = newSigSout.getDate_res(); // NULL dem_S.setId_intervenant(intervenant); String date_aff = newSigSout.getDate_aff(); String date_aff_H = newSigSout.getH_date_aff(); String date_aff_M = newSigSout.getM_date_aff(); String new_date_aff = getCorrectDate(date_aff, date_aff_H, date_aff_M); dem_S.setDate_aff(new_date_aff); dem_S.setLib_dem(newSigSout.getLib_dem()); dem_S.setRef_cli(new Integer(newSigSout.getRefus_client()).intValue()); dem_S.setDem_oga(new Integer(newSigSout.getDem_OGA()).intValue()); dem_S.setTps_eff(newSigSout.getTps_eff()); dem_S.setCommentaire(newSigSout.getCommentaire()); dem_S.setId_tache(newSigSout.getTache()); int etat = 1; if (!s_date_pec.trim().equals("")) { String date_pec = newSigSout.getDate_pec(); String date_pec_H = newSigSout.getH_date_pec(); String date_pec_M = newSigSout.getM_date_pec(); String new_date_pec = getCorrectDate(date_pec, date_pec_H, date_pec_M); dem_S.setDate_pec(new_date_pec); etat = 2; } if (!s_date_res.trim().equals("")) { String date_res = newSigSout.getDate_res(); String date_res_H = newSigSout.getH_date_res(); String date_res_M = newSigSout.getM_date_res(); String new_date_res = getCorrectDate(date_res, date_res_H, date_res_M); dem_S.setDate_res(new_date_res); etat = 3; } if (!s_date_clo.trim().equals("")) { String date_clo = newSigSout.getDate_clo(); String date_clo_H = newSigSout.getH_date_clo(); String date_clo_M = newSigSout.getM_date_clo(); String new_date_clo = getCorrectDate(date_clo, date_clo_H, date_clo_M); dem_S.setDate_clo(new_date_clo); etat = 4; } System.out.println("avant"); //dem_S.setId_criticite(new Integer(newSigSout.getCriticite()).intValue()); System.out.println("criticite ok :" + dem_S.getId_criticite()); //session.save(dem_S); System.out.println("apres"); // T_Application application = (T_Application) session.load( T_Application.class, new Integer(appli).intValue()); application.addFicheS(dem_S); T_Intervenant tIntervenant = (T_Intervenant) session.load( T_Intervenant.class, intervenant); tIntervenant.addFicheS(dem_S); T_Criticite criticite = (T_Criticite) session.load(T_Criticite.class, new Integer(newSigSout.getCriticite()).intValue()); criticite.addFicheS(dem_S); T_Orig_Dem orig_dem = (T_Orig_Dem) session.load(T_Orig_Dem.class, new Integer(newSigSout.getOrig_dem()).intValue()); orig_dem.addFicheS(dem_S); T_Type_Peri type_peri = (T_Type_Peri) session.load(T_Type_Peri.class, new Integer(newSigSout.getType_peri()).intValue()); type_peri.addFicheS(dem_S); T_Tache tache = (T_Tache) session.load(T_Tache.class, "2.2.1"); tache.addFicheS(dem_S); T_Etat tEtat = (T_Etat) session.load(T_Etat.class, etat); tEtat.addFicheS(dem_S); // System.out.println("Object persisted to the database."); tx.commit(); System.out.println("commit ok"); session.flush(); System.out.println("flush ok"); session.close(); System.out.println("close ok"); return dem_S.getId(); }
J'obtiens l'erreur suivante :
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="tables.T_Application" table="t_application"> <id name="idApplication" type="integer" column="id_application"> <generator class="increment" /> </id> <property name="libApplication"> <column name="lib_application" /> </property> <set name="ficheS" cascade="all"> <key column="id_application" /> <one-to-many class="tables.T_Dem_S" /> </set> <set name="ficheOS" cascade="all"> <key column="id_application" /> <one-to-many class="tables.T_Dem_OS" /> </set> </class> <class name="tables.T_Criticite" table="t_criticite"> <id name="idCriticite" type="integer" column="id_criticite"> <generator class="increment" /> </id> <property name="libCriticite"> <column name="lib_criticite" /> </property> <set name="ficheS" cascade="all"> <key column="id_criticite" /> <one-to-many class="tables.T_Dem_S" /> </set> </class> <class name="tables.T_Domaine" table="t_domaine"> <id name="idDomaine" type="integer" column="id_domaine"> <generator class="increment" /> </id> <property name="libDomaine"> <column name="lib_domaine" /> </property> <set name="intervenant" cascade="all"> <key column="id_domaine" /> <one-to-many class="tables.T_Intervenant" /> </set> </class> <class name="tables.T_Etat" table="t_etat"> <id name="idEtat" type="integer" column="id_etat"> <generator class="increment" /> </id> <property name="libEtat"> <column name="lib_etat" /> </property> <set name="ficheS" cascade="all"> <key column="id_etat" /> <one-to-many class="tables.T_Dem_S" /> </set> <set name="ficheOS" cascade="all"> <key column="id_etat" /> <one-to-many class="tables.T_Dem_OS" /> </set> </class> <class name="tables.T_Groupe" table="t_groupe"> <id name="idGroupe" type="integer" column="id_groupe"> <generator class="increment" /> </id> <property name="libGroupe"> <column name="lib_groupe" /> </property> <set name="intervenant" cascade="all"> <key column="id_groupe" /> <one-to-many class="tables.T_Intervenant" /> </set> </class> <class name="tables.T_Orig_Dem" table="t_orig_dem"> <id name="idOrig_Dem" type="integer" column="id_orig_dem"> <generator class="increment" /> </id> <property name="libOrig_Dem"> <column name="lib_orig_dem" /> </property> <set name="ficheS" cascade="all"> <key column="id_orig_dem" /> <one-to-many class="tables.T_Dem_S" /> </set> <set name="ficheOS" cascade="all"> <key column="id_orig_dem" /> <one-to-many class="tables.T_Dem_OS" /> </set> </class> <class name="tables.T_Tache" table="t_tache"> <id name="idTache" type="string" column="id_tache" /> <property name="libTache"> <column name="lib_tache" /> </property> <set name="ficheS" cascade="all"> <key column="id_tache" /> <one-to-many class="tables.T_Dem_S" /> </set> </class> <class name="tables.T_Type_Dem" table="t_type_dem"> <id name="idType_Dem" type="integer" column="id_type_dem"> <generator class="increment" /> </id> <property name="libType_Dem"> <column name="lib_type_dem" /> </property> <set name="ficheOS" cascade="all"> <key column="id_type_dem" /> <one-to-many class="tables.T_Dem_OS" /> </set> </class> <class name="tables.T_Type_Peri" table="t_type_peri"> <id name="idType_Peri" type="integer" column="id_type_peri"> <generator class="increment" /> </id> <property name="libType_Peri"> <column name="lib_type_peri" /> </property> <set name="ficheS" cascade="all"> <key column="id_type_peri" /> <one-to-many class="tables.T_Dem_S" /> </set> <set name="ficheOS" cascade="all"> <key column="id_type_peri" /> <one-to-many class="tables.T_Dem_OS" /> </set> </class> <class name="tables.T_Intervenant" table="t_intervenant"> <id name="idIntervenant" column="id_intervenant" /> <property name="libIntervenant"> <column name="prenom_nom" /> </property> <property name="actif"> <column name="actif" /> </property> <property name="id_groupe" /> <property name="id_domaine" /> <set name="ficheS" cascade="all"> <key column="id_intervenant" /> <one-to-many class="tables.T_Dem_S" /> </set> <set name="ficheOS" cascade="all"> <key column="id_intervenant" /> <one-to-many class="tables.T_Dem_OS" /> </set> </class> <class name="tables.T_Dem_S" table="t_soutien"> <id name="id" type="integer" column="id"> <generator class="increment" /> </id> <property name="date_aff"> <column name="date_aff" /> </property> <property name="date_pec"> <column name="date_pec" /> </property> <property name="date_res"> <column name="date_res" /> </property> <property name="date_clo"> <column name="date_clo" /> </property> <property name="lib_dem"> <column name="lib_dem" /> </property> <property name="tps_eff"> <column name="tps_eff" /> </property> <property name="dem_oga"> <column name="dem_oga" /> </property> <property name="ref_cli"> <column name="ref_cli" /> </property> <property name="commentaire"> <column name="commentaire" /> </property> <many-to-one name="id_criticite" class="tables.T_Criticite" /> <many-to-one name="id_orig_dem" class="tables.T_Orig_Dem" /> <many-to-one name="id_application" class="tables.T_Application" /> <many-to-one name="id_type_peri" class="tables.T_Type_Peri" /> <many-to-one name="id_tache" class="tables.T_Tache" /> <many-to-one name="id_etat" class="tables.T_Etat" /> <many-to-one name="id_intervenant" class="tables.T_Intervenant" /> <!-- <property name="id_criticite" /> <property name="id_orig_dem" /> <property name="id_application" /> <property name="id_type_peri" /> <property name="id_tache" /> <property name="id_etat" /> <property name="id_intervenant" /> --> </class> <class name="tables.T_Dem_OS" table="t_os"> <id name="id" type="integer" column="id"> <generator class="increment" /> </id> <property name="date_aff"> <column name="date_aff" /> </property> <property name="date_sou"> <column name="date_sou" /> </property> <property name="date_liv"> <column name="date_liv" /> </property> <property name="date_clo"> <column name="date_clo" /> </property> <property name="lib_dem"> <column name="lib_dem" /> </property> <property name="tps_est"> <column name="tps_est" /> </property> <property name="tps_eff"> <column name="tps_eff" /> </property> <property name="commentaire"> <column name="commentaire" /> </property> <many-to-one name="id_orig_dem" class="tables.T_Orig_Dem" not-null="true" /> <many-to-one name="id_application" class="tables.T_Application" not-null="true" /> <many-to-one name="id_type_peri" class="tables.T_Type_Peri" not-null="true" /> <many-to-one name="id_type_dem" class="tables.T_Type_Dem" not-null="true" /> <many-to-one name="id_etat" class="tables.T_Etat" not-null="true" /> <many-to-one name="id_intervenant" class="tables.T_Intervenant" not-null="true" /> <!-- <property name="id_orig_dem" /> <property name="id_application" /> <property name="id_type_peri" /> <property name="id_type_dem" /> <property name="id_etat" /> <property name="id_intervenant" /> --> </class> </hibernate-mapping>
Merci de bien vouloir m'aider, j'ai vraiment du mal...
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 javax.servlet.ServletException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of tables.T_Dem_S.setId_criticite org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:763) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) sun.reflect.GeneratedMethodAccessor124.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:585) org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243) java.security.AccessController.doPrivileged(Native Method) javax.security.auth.Subject.doAsPrivileged(Subject.java:517) org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275) org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161) root cause org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of tables.T_Dem_S.setId_criticite org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:215) org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:185) org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3232) org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129) org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842) org.hibernate.loader.Loader.doQuery(Loader.java:717) org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) org.hibernate.loader.Loader.loadCollection(Loader.java:1919) org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36) org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520) org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60) org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1676) org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344) org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:183) org.hibernate.collection.PersistentSet.add(PersistentSet.java:165) tables.T_Criticite.addFicheS(Unknown Source) tables.T_Criticite$$FastClassByCGLIB$$98f8e352.invoke(<generated>) net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:161) tables.T_Criticite$$EnhancerByCGLIB$$27fafb49_8.addFicheS(<generated>) sig.Sig_SoutService.createNewDemSout(Unknown Source) utils.InsertSigAction.execute(Unknown Source) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419) org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) javax.servlet.http.HttpServlet.service(HttpServlet.java:763) javax.servlet.http.HttpServlet.service(HttpServlet.java:856) sun.reflect.GeneratedMethodAccessor124.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:585) org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:243) java.security.AccessController.doPrivileged(Native Method) javax.security.auth.Subject.doAsPrivileged(Subject.java:517) org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:275) org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:161)![]()
Partager