Skip to content

Commit 49c145e

Browse files
committed
Adjust MyBatisSystemException to Spring 6
Since Spring 6, `org.springframework.core.NestedRuntimeException` no longer includes the message of the wrapped exception. spring-projects/spring-framework#25162 Should fix mybatisgh-887
1 parent 8d8e362 commit 49c145e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2022 the original author or authors.
2+
* Copyright 2010-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,6 +85,7 @@ public DataAccessException translateExceptionIfPossible(RuntimeException e) {
8585
if (e.getCause() instanceof PersistenceException) {
8686
e = (PersistenceException) e.getCause();
8787
}
88+
String msg = e.getMessage();
8889
if (e.getCause() instanceof SQLException) {
8990
this.initExceptionTranslator();
9091
String task = e.getMessage() + "\n";
@@ -94,7 +95,7 @@ public DataAccessException translateExceptionIfPossible(RuntimeException e) {
9495
} else if (e.getCause() instanceof TransactionException) {
9596
throw (TransactionException) e.getCause();
9697
}
97-
return new MyBatisSystemException(e);
98+
return new MyBatisSystemException(msg, e);
9899
}
99100
return null;
100101
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2022 the original author or authors.
2+
* Copyright 2010-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,8 +31,8 @@ public class MyBatisSystemException extends UncategorizedDataAccessException {
3131

3232
private static final long serialVersionUID = -5284728621670758939L;
3333

34-
public MyBatisSystemException(Throwable cause) {
35-
super(null, cause);
34+
public MyBatisSystemException(String msg, Throwable cause) {
35+
super(msg, cause);
3636
}
3737

3838
}

0 commit comments

Comments
 (0)