File tree 3 files changed +22
-2
lines changed
main/java/org/springframework/session/jdbc
config/annotation/web/http
test/java/org/springframework/session/jdbc/config/annotation/web/http
3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2014-2020 the original author or authors.
2
+ * Copyright 2014-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -500,6 +500,9 @@ public int getBatchSize() {
500
500
catch (DataIntegrityViolationException ex ) {
501
501
// parent record not found - we are ignoring this error because we
502
502
// assume that a concurrent request has removed the session
503
+ if (logger .isTraceEnabled ()) {
504
+ logger .trace ("Not able to create session attributes" , ex );
505
+ }
503
506
}
504
507
}
505
508
else {
@@ -517,6 +520,9 @@ public int getBatchSize() {
517
520
catch (DataIntegrityViolationException ex ) {
518
521
// parent record not found - we are ignoring this error because we
519
522
// assume that a concurrent request has removed the session
523
+ if (logger .isTraceEnabled ()) {
524
+ logger .trace ("Not able to create session attributes" , ex );
525
+ }
520
526
}
521
527
}
522
528
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2014-2019 the original author or authors.
2
+ * Copyright 2014-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
39
39
import org .springframework .jdbc .core .JdbcTemplate ;
40
40
import org .springframework .jdbc .support .JdbcUtils ;
41
41
import org .springframework .jdbc .support .MetaDataAccessException ;
42
+ import org .springframework .jdbc .support .SQLErrorCodeSQLExceptionTranslator ;
42
43
import org .springframework .jdbc .support .lob .DefaultLobHandler ;
43
44
import org .springframework .jdbc .support .lob .LobHandler ;
44
45
import org .springframework .scheduling .annotation .EnableScheduling ;
@@ -259,6 +260,7 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
259
260
260
261
private static JdbcTemplate createJdbcTemplate (DataSource dataSource ) {
261
262
JdbcTemplate jdbcTemplate = new JdbcTemplate (dataSource );
263
+ jdbcTemplate .setExceptionTranslator (new SQLErrorCodeSQLExceptionTranslator (dataSource ));
262
264
jdbcTemplate .afterPropertiesSet ();
263
265
return jdbcTemplate ;
264
266
}
Original file line number Diff line number Diff line change 32
32
import org .springframework .core .annotation .Order ;
33
33
import org .springframework .core .convert .ConversionService ;
34
34
import org .springframework .jdbc .core .JdbcOperations ;
35
+ import org .springframework .jdbc .core .JdbcTemplate ;
36
+ import org .springframework .jdbc .support .SQLErrorCodeSQLExceptionTranslator ;
35
37
import org .springframework .jdbc .support .lob .LobHandler ;
36
38
import org .springframework .mock .env .MockEnvironment ;
37
39
import org .springframework .session .FlushMode ;
@@ -300,6 +302,16 @@ void sessionRepositoryCustomizer() {
300
302
MAX_INACTIVE_INTERVAL_IN_SECONDS );
301
303
}
302
304
305
+ @ Test
306
+ void defaultConfigurationJdbcTemplateHasExpectedExceptionTranslator () {
307
+ registerAndRefresh (DataSourceConfiguration .class , DefaultConfiguration .class );
308
+
309
+ JdbcIndexedSessionRepository repository = this .context .getBean (JdbcIndexedSessionRepository .class );
310
+ JdbcTemplate jdbcTemplate = (JdbcTemplate ) ReflectionTestUtils .getField (repository , "jdbcOperations" );
311
+ assertThat (jdbcTemplate ).isNotNull ();
312
+ assertThat (jdbcTemplate .getExceptionTranslator ()).isInstanceOf (SQLErrorCodeSQLExceptionTranslator .class );
313
+ }
314
+
303
315
private void registerAndRefresh (Class <?>... annotatedClasses ) {
304
316
this .context .register (annotatedClasses );
305
317
this .context .refresh ();
You can’t perform that action at this time.
0 commit comments