質問編集履歴
2
-
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
【spring】"defaultAutoCommit" value="false"時のcommitのやり方
|
1
|
+
【spring】"defaultAutoCommit" value="false"時のcommitのやり方をご教授いただきたいです。
|
test
CHANGED
File without changes
|
1
A-pZ様:アドバイスありがとうございます。 レコードを追加しているクラス・設定を追記しました。まだ至らない点があればもう少しteratailを覗いて改めて投稿いたします。
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
【spring】"defaultAutoCommit" value="false"時のcommitのやり方
|
5
|
+
【spring】"defaultAutoCommit" value="false"時のcommitのやり方をご教授いただきたいです。
|
6
6
|
|
7
7
|
|
8
8
|
|
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
@Transactionalがうまくいかなかったので他の方法を模索しているのですが、
|
16
16
|
|
17
|
-
そもそも「Bean定義ファイル」にてdefaultAutoCommitをfalseにしているとプログラムが正常に終了してもcommitがされませんでした。※("commit")の処理を入れても同様
|
17
|
+
そもそも「Bean定義ファイル」にてdefaultAutoCommitをfalseにしていると、プログラムが正常に終了してもcommitがされませんでした。※("commit")のsql処理を入れても同様
|
18
18
|
|
19
19
|
|
20
20
|
|
@@ -52,6 +52,490 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
+
【コントローラークラス】
|
56
|
+
|
57
|
+
@RequestMapping(value="/form",method=RequestMethod.POST,params="regist")
|
58
|
+
|
59
|
+
public String toSubmit(OrdererModel oModel,ProductModel pModel,Model model,HttpServletRequest request) {
|
60
|
+
|
61
|
+
HttpSession session = request.getSession();
|
62
|
+
|
63
|
+
try {
|
64
|
+
|
65
|
+
//DAOクラスのメソッド呼び出し
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
trans.toSubmit(oModel, pModel, model, request,jdbcTemplate);
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
}catch(Exception e) {
|
76
|
+
|
77
|
+
e.printStackTrace();
|
78
|
+
|
79
|
+
model.addAttribute("error_title","DBエラー");
|
80
|
+
|
81
|
+
model.addAttribute("error_message","DBエラーが発生しました。<br/>管理者に連絡してください。");
|
82
|
+
|
83
|
+
return "error";
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
session.invalidate();
|
88
|
+
|
89
|
+
return "reception_complete";
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
【コントローラークラスから呼ばれるDAOクラス】
|
96
|
+
|
97
|
+
public void toSubmit(OrdererModel oModel,ProductModel pModel,Model model,HttpServletRequest request,JdbcTemplate jdbcTemplate){
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
HttpSession session = request.getSession();
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
//呼び出されるメソッド
|
106
|
+
|
107
|
+
jdbcTemplate.update("INSERT INTO orderer(l_name,f_name,l_name_kana,f_name_kana,prefecture,city,o_address,tel,email)VALUES(?,?,?,?,?,?,?,?,?)",oModel.getL_name(),oModel.getF_name(),oModel.getL_name_kana(),oModel.getF_name_kana(),oModel.getPrefecture(),oModel.getCity(),oModel.getO_address(),oModel.getTel(),oModel.getEmail());
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
↑SQL文がやたら長いですが、autocommit=falseをしないときは正常にinsertできます。
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
【pom.xml】
|
116
|
+
|
117
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
118
|
+
|
119
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
120
|
+
|
121
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
122
|
+
|
123
|
+
<modelVersion>4.0.0</modelVersion>
|
124
|
+
|
125
|
+
<groupId>jp.ken</groupId>
|
126
|
+
|
127
|
+
<artifactId>validation</artifactId>
|
128
|
+
|
129
|
+
<name>ValidateionSample</name>
|
130
|
+
|
131
|
+
<packaging>war</packaging>
|
132
|
+
|
133
|
+
<version>1.0.0-BUILD-SNAPSHOT</version>
|
134
|
+
|
135
|
+
<properties>
|
136
|
+
|
137
|
+
<java-version>1.8</java-version>
|
138
|
+
|
139
|
+
<org.springframework-version>4.2.3.RELEASE</org.springframework-version>
|
140
|
+
|
141
|
+
<org.aspectj-version>1.6.10</org.aspectj-version>
|
142
|
+
|
143
|
+
<org.slf4j-version>1.6.6</org.slf4j-version>
|
144
|
+
|
145
|
+
</properties>
|
146
|
+
|
147
|
+
<dependencies>
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
<!-- Spring -->
|
152
|
+
|
153
|
+
<dependency>
|
154
|
+
|
155
|
+
<groupId>org.springframework</groupId>
|
156
|
+
|
157
|
+
<artifactId>spring-core</artifactId>
|
158
|
+
|
159
|
+
<version>4.2.3.RELEASE</version>
|
160
|
+
|
161
|
+
</dependency>
|
162
|
+
|
163
|
+
<dependency>
|
164
|
+
|
165
|
+
<groupId>org.apache.commons</groupId>
|
166
|
+
|
167
|
+
<artifactId>commons-dbcp2</artifactId>
|
168
|
+
|
169
|
+
<version>2.5.0</version>
|
170
|
+
|
171
|
+
</dependency>
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
<dependency>
|
176
|
+
|
177
|
+
<groupId>javax.validation</groupId>
|
178
|
+
|
179
|
+
<artifactId>validation-api</artifactId>
|
180
|
+
|
181
|
+
<version>1.1.0.Final</version>
|
182
|
+
|
183
|
+
</dependency>
|
184
|
+
|
185
|
+
<dependency>
|
186
|
+
|
187
|
+
<groupId>org.hibernate</groupId>
|
188
|
+
|
189
|
+
<artifactId>hibernate-validator</artifactId>
|
190
|
+
|
191
|
+
<version>5.0.1.Final</version>
|
192
|
+
|
193
|
+
</dependency>
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
<dependency>
|
198
|
+
|
199
|
+
<groupId>org.springframework</groupId>
|
200
|
+
|
201
|
+
<artifactId>spring-jdbc</artifactId>
|
202
|
+
|
203
|
+
<version>${org.springframework-version}</version>
|
204
|
+
|
205
|
+
</dependency>
|
206
|
+
|
207
|
+
<dependency>
|
208
|
+
|
209
|
+
<groupId>mysql</groupId>
|
210
|
+
|
211
|
+
<artifactId>mysql-connector-java</artifactId>
|
212
|
+
|
213
|
+
<version>5.1.45</version>
|
214
|
+
|
215
|
+
</dependency>
|
216
|
+
|
217
|
+
<dependency>
|
218
|
+
|
219
|
+
<groupId>org.springframework</groupId>
|
220
|
+
|
221
|
+
<artifactId>spring-context</artifactId>
|
222
|
+
|
223
|
+
<version>${org.springframework-version}</version>
|
224
|
+
|
225
|
+
<exclusions>
|
226
|
+
|
227
|
+
<!-- Exclude Commons Logging in favor of SLF4j -->
|
228
|
+
|
229
|
+
<exclusion>
|
230
|
+
|
231
|
+
<groupId>commons-logging</groupId>
|
232
|
+
|
233
|
+
<artifactId>commons-logging</artifactId>
|
234
|
+
|
235
|
+
</exclusion>
|
236
|
+
|
237
|
+
</exclusions>
|
238
|
+
|
239
|
+
</dependency>
|
240
|
+
|
241
|
+
<dependency>
|
242
|
+
|
243
|
+
<groupId>org.springframework</groupId>
|
244
|
+
|
245
|
+
<artifactId>spring-webmvc</artifactId>
|
246
|
+
|
247
|
+
<version>${org.springframework-version}</version>
|
248
|
+
|
249
|
+
</dependency>
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
<!-- AspectJ -->
|
254
|
+
|
255
|
+
<dependency>
|
256
|
+
|
257
|
+
<groupId>org.aspectj</groupId>
|
258
|
+
|
259
|
+
<artifactId>aspectjrt</artifactId>
|
260
|
+
|
261
|
+
<version>${org.aspectj-version}</version>
|
262
|
+
|
263
|
+
</dependency>
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
<!-- Logging -->
|
268
|
+
|
269
|
+
<dependency>
|
270
|
+
|
271
|
+
<groupId>org.slf4j</groupId>
|
272
|
+
|
273
|
+
<artifactId>slf4j-api</artifactId>
|
274
|
+
|
275
|
+
<version>${org.slf4j-version}</version>
|
276
|
+
|
277
|
+
</dependency>
|
278
|
+
|
279
|
+
<dependency>
|
280
|
+
|
281
|
+
<groupId>org.slf4j</groupId>
|
282
|
+
|
283
|
+
<artifactId>jcl-over-slf4j</artifactId>
|
284
|
+
|
285
|
+
<version>${org.slf4j-version}</version>
|
286
|
+
|
287
|
+
<scope>runtime</scope>
|
288
|
+
|
289
|
+
</dependency>
|
290
|
+
|
291
|
+
<dependency>
|
292
|
+
|
293
|
+
<groupId>org.slf4j</groupId>
|
294
|
+
|
295
|
+
<artifactId>slf4j-log4j12</artifactId>
|
296
|
+
|
297
|
+
<version>${org.slf4j-version}</version>
|
298
|
+
|
299
|
+
<scope>runtime</scope>
|
300
|
+
|
301
|
+
</dependency>
|
302
|
+
|
303
|
+
<dependency>
|
304
|
+
|
305
|
+
<groupId>log4j</groupId>
|
306
|
+
|
307
|
+
<artifactId>log4j</artifactId>
|
308
|
+
|
309
|
+
<version>1.2.15</version>
|
310
|
+
|
311
|
+
<exclusions>
|
312
|
+
|
313
|
+
<exclusion>
|
314
|
+
|
315
|
+
<groupId>javax.mail</groupId>
|
316
|
+
|
317
|
+
<artifactId>mail</artifactId>
|
318
|
+
|
319
|
+
</exclusion>
|
320
|
+
|
321
|
+
<exclusion>
|
322
|
+
|
323
|
+
<groupId>javax.jms</groupId>
|
324
|
+
|
325
|
+
<artifactId>jms</artifactId>
|
326
|
+
|
327
|
+
</exclusion>
|
328
|
+
|
329
|
+
<exclusion>
|
330
|
+
|
331
|
+
<groupId>com.sun.jdmk</groupId>
|
332
|
+
|
333
|
+
<artifactId>jmxtools</artifactId>
|
334
|
+
|
335
|
+
</exclusion>
|
336
|
+
|
337
|
+
<exclusion>
|
338
|
+
|
339
|
+
<groupId>com.sun.jmx</groupId>
|
340
|
+
|
341
|
+
<artifactId>jmxri</artifactId>
|
342
|
+
|
343
|
+
</exclusion>
|
344
|
+
|
345
|
+
</exclusions>
|
346
|
+
|
347
|
+
<scope>runtime</scope>
|
348
|
+
|
349
|
+
</dependency>
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
<!-- @Inject -->
|
354
|
+
|
355
|
+
<dependency>
|
356
|
+
|
357
|
+
<groupId>javax.inject</groupId>
|
358
|
+
|
359
|
+
<artifactId>javax.inject</artifactId>
|
360
|
+
|
361
|
+
<version>1</version>
|
362
|
+
|
363
|
+
</dependency>
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
<!-- Servlet -->
|
368
|
+
|
369
|
+
<dependency>
|
370
|
+
|
371
|
+
<groupId>javax.servlet</groupId>
|
372
|
+
|
373
|
+
<artifactId>servlet-api</artifactId>
|
374
|
+
|
375
|
+
<version>2.5</version>
|
376
|
+
|
377
|
+
<scope>provided</scope>
|
378
|
+
|
379
|
+
</dependency>
|
380
|
+
|
381
|
+
<dependency>
|
382
|
+
|
383
|
+
<groupId>javax.servlet.jsp</groupId>
|
384
|
+
|
385
|
+
<artifactId>jsp-api</artifactId>
|
386
|
+
|
387
|
+
<version>2.1</version>
|
388
|
+
|
389
|
+
<scope>provided</scope>
|
390
|
+
|
391
|
+
</dependency>
|
392
|
+
|
393
|
+
<dependency>
|
394
|
+
|
395
|
+
<groupId>javax.servlet</groupId>
|
396
|
+
|
397
|
+
<artifactId>jstl</artifactId>
|
398
|
+
|
399
|
+
<version>1.2</version>
|
400
|
+
|
401
|
+
</dependency>
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
<!-- Test -->
|
406
|
+
|
407
|
+
<dependency>
|
408
|
+
|
409
|
+
<groupId>junit</groupId>
|
410
|
+
|
411
|
+
<artifactId>junit</artifactId>
|
412
|
+
|
413
|
+
<version>4.7</version>
|
414
|
+
|
415
|
+
<scope>test</scope>
|
416
|
+
|
417
|
+
</dependency>
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
<!-- https://mvnrepository.com/artifact/aopalliance/aopalliance -->
|
422
|
+
|
423
|
+
<dependency>
|
424
|
+
|
425
|
+
<groupId>aopalliance</groupId>
|
426
|
+
|
427
|
+
<artifactId>aopalliance</artifactId>
|
428
|
+
|
429
|
+
<version>1.0</version>
|
430
|
+
|
431
|
+
</dependency>
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
|
436
|
+
|
437
|
+
<dependency>
|
438
|
+
|
439
|
+
<groupId>org.aspectj</groupId>
|
440
|
+
|
441
|
+
<artifactId>aspectjweaver</artifactId>
|
442
|
+
|
443
|
+
<version>1.9.2</version>
|
444
|
+
|
445
|
+
</dependency>
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
</dependencies>
|
454
|
+
|
455
|
+
<build>
|
456
|
+
|
457
|
+
<plugins>
|
458
|
+
|
459
|
+
<plugin>
|
460
|
+
|
461
|
+
<artifactId>maven-eclipse-plugin</artifactId>
|
462
|
+
|
463
|
+
<version>2.9</version>
|
464
|
+
|
465
|
+
<configuration>
|
466
|
+
|
467
|
+
<additionalProjectnatures>
|
468
|
+
|
469
|
+
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
|
470
|
+
|
471
|
+
</additionalProjectnatures>
|
472
|
+
|
473
|
+
<additionalBuildcommands>
|
474
|
+
|
475
|
+
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
|
476
|
+
|
477
|
+
</additionalBuildcommands>
|
478
|
+
|
479
|
+
<downloadSources>true</downloadSources>
|
480
|
+
|
481
|
+
<downloadJavadocs>true</downloadJavadocs>
|
482
|
+
|
483
|
+
</configuration>
|
484
|
+
|
485
|
+
</plugin>
|
486
|
+
|
487
|
+
<plugin>
|
488
|
+
|
489
|
+
<groupId>org.apache.maven.plugins</groupId>
|
490
|
+
|
491
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
492
|
+
|
493
|
+
<version>2.5.1</version>
|
494
|
+
|
495
|
+
<configuration>
|
496
|
+
|
497
|
+
<source>1.8</source>
|
498
|
+
|
499
|
+
<target>1.8</target>
|
500
|
+
|
501
|
+
<compilerArgument>-Xlint:all</compilerArgument>
|
502
|
+
|
503
|
+
<showWarnings>true</showWarnings>
|
504
|
+
|
505
|
+
<showDeprecation>true</showDeprecation>
|
506
|
+
|
507
|
+
</configuration>
|
508
|
+
|
509
|
+
</plugin>
|
510
|
+
|
511
|
+
<plugin>
|
512
|
+
|
513
|
+
<groupId>org.codehaus.mojo</groupId>
|
514
|
+
|
515
|
+
<artifactId>exec-maven-plugin</artifactId>
|
516
|
+
|
517
|
+
<version>1.2.1</version>
|
518
|
+
|
519
|
+
<configuration>
|
520
|
+
|
521
|
+
<mainClass>org.test.int1.Main</mainClass>
|
522
|
+
|
523
|
+
</configuration>
|
524
|
+
|
525
|
+
</plugin>
|
526
|
+
|
527
|
+
</plugins>
|
528
|
+
|
529
|
+
</build>
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
</project>
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
|
538
|
+
|
55
539
|
|
56
540
|
|
57
541
|
プログラミングを始めて3か月です。至らない点がありましたら申し訳ございませんが、お知恵を貸していただけると幸いです。
|