Skip to content

Commit 923ef6c

Browse files
committed
1 parent d71643c commit 923ef6c

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/main/java/org/mybatis/spring/MyBatisExceptionTranslator.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
*/
3838
public class MyBatisExceptionTranslator implements PersistenceExceptionTranslator {
3939

40-
private final Object $lock = new Object();
41-
4240
private final DataSource dataSource;
4341

4442
private SQLExceptionTranslator exceptionTranslator;
@@ -63,11 +61,7 @@ public MyBatisExceptionTranslator(DataSource dataSource, boolean exceptionTransl
6361
*/
6462
public DataAccessException translateExceptionIfPossible(RuntimeException e) {
6563
if (e.getCause() instanceof SQLException) {
66-
if (this.exceptionTranslator == null) {
67-
synchronized (this.$lock) {
68-
this.initExceptionTranslator();
69-
}
70-
}
64+
this.initExceptionTranslator();
7165
return this.exceptionTranslator.translate(e.getMessage() + "\n", null, (SQLException) e.getCause());
7266
}
7367
return new MyBatisSystemException(e);
@@ -76,8 +70,10 @@ public DataAccessException translateExceptionIfPossible(RuntimeException e) {
7670
/**
7771
* Initializes the internal translator reference.
7872
*/
79-
private void initExceptionTranslator() {
80-
this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(this.dataSource);
73+
private synchronized void initExceptionTranslator() {
74+
if (this.exceptionTranslator == null) {
75+
this.exceptionTranslator = new SQLErrorCodeSQLExceptionTranslator(this.dataSource);
76+
}
8177
}
8278

8379
}

0 commit comments

Comments
 (0)