Skip to content

Commit f6c28a6

Browse files
committed
Put the direct cause in the error message
And let the maven plugins do the cleanup.
1 parent c29ce33 commit f6c28a6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,10 @@ private boolean applyColumnOrderBasedConstructorAutomapping(ResultSetWrapper rsw
784784
List<Object> constructorArgs, Constructor<?> constructor, boolean foundValues) throws SQLException {
785785
Class<?>[] parameterTypes = constructor.getParameterTypes();
786786

787-
// constructor parameter is allowed to be less than or equal to the number of result set columns, but not greater than
788787
if (parameterTypes.length > rsw.getClassNames().size()) {
789788
throw new ExecutorException(MessageFormat.format(
790-
"Column order based constructor auto-mapping of ''{0}'' failed. Because result set type is ''{1}''.",
791-
constructor, rsw.getClassNames()));
789+
"Constructor auto-mapping of ''{0}'' failed. The constructor takes ''{1}'' arguments, but there are only ''{2}'' columns in the result set.",
790+
constructor, parameterTypes.length, rsw.getClassNames().size()));
792791
}
793792

794793
for (int i = 0; i < parameterTypes.length; i++) {

src/test/java/org/apache/ibatis/submitted/column_order_based_constructor_automapping/ColumnOrderBasedConstructorAutomappingTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import static org.junit.jupiter.api.Assertions.assertNull;
2121
import static org.junit.jupiter.api.Assertions.assertThrows;
2222
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
2324
import java.io.Reader;
25+
import java.text.MessageFormat;
2426
import java.util.List;
27+
2528
import org.apache.ibatis.BaseDataTest;
2629
import org.apache.ibatis.exceptions.PersistenceException;
2730
import org.apache.ibatis.io.Resources;
@@ -39,14 +42,14 @@ class ColumnOrderBasedConstructorAutomappingTest {
3942
static void setUp() throws Exception {
4043
// create an SqlSessionFactory
4144
try (Reader reader = Resources.getResourceAsReader(
42-
"org/apache/ibatis/submitted/column_order_based_constructor_automapping/mybatis-config.xml")) {
45+
"org/apache/ibatis/submitted/column_order_based_constructor_automapping/mybatis-config.xml")) {
4346
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
4447
sqlSessionFactory.getConfiguration().setArgNameBasedConstructorAutoMapping(false);
4548
}
4649

4750
// populate in-memory database
4851
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
49-
"org/apache/ibatis/submitted/column_order_based_constructor_automapping/CreateDB.sql");
52+
"org/apache/ibatis/submitted/column_order_based_constructor_automapping/CreateDB.sql");
5053
}
5154

5255
@Test
@@ -120,10 +123,14 @@ void shouldNotHandleConstructorGreaterThanResultSet() {
120123
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
121124
Mapper mapper = sqlSession.getMapper(Mapper.class);
122125

123-
PersistenceException persistenceException = assertThrows(PersistenceException.class, mapper::finaAllByConstructorGreaterThanResultSet);
126+
PersistenceException persistenceException = assertThrows(PersistenceException.class,
127+
mapper::finaAllByConstructorGreaterThanResultSet);
124128
assertNotNull(persistenceException);
125-
assertNotNull(persistenceException.getMessage());
126-
assertTrue(persistenceException.getMessage().contains("Column order based constructor auto-mapping of"));
129+
String message = persistenceException.getMessage();
130+
assertNotNull(message);
131+
assertTrue(message.contains(MessageFormat.format(
132+
"Constructor auto-mapping of ''{0}'' failed. The constructor takes ''{1}'' arguments, but there are only ''{2}'' columns in the result set.",
133+
UserConstructorGreaterThanResultSet.class.getConstructors()[0], 4, 3)));
127134
}
128135
}
129136
}

0 commit comments

Comments
 (0)