diff --git a/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java b/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java index fd6ccdf3745..e6b358aa2e3 100644 --- a/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java +++ b/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -117,14 +117,11 @@ private TypeHandler[] getTypeHandlers(TypeHandlerRegistry typeHandlerRegistry TypeHandler[] typeHandlers = new TypeHandler[keyProperties.length]; for (int i = 0; i < keyProperties.length; i++) { if (metaParam.hasSetter(keyProperties[i])) { - TypeHandler th; - try { - Class keyPropertyType = metaParam.getSetterType(keyProperties[i]); - th = typeHandlerRegistry.getTypeHandler(keyPropertyType, JdbcType.forCode(rsmd.getColumnType(i + 1))); - } catch (BindingException e) { - th = null; - } - typeHandlers[i] = th; + Class keyPropertyType = metaParam.getSetterType(keyProperties[i]); + typeHandlers[i] = typeHandlerRegistry.getTypeHandler(keyPropertyType, JdbcType.forCode(rsmd.getColumnType(i + 1))); + } else { + throw new ExecutorException("No setter found for the keyProperty '" + keyProperties[i] + "' in '" + + metaParam.getOriginalObject().getClass().getName() + "'."); } } return typeHandlers; diff --git a/src/test/java/org/apache/ibatis/submitted/keygen/Jdbc3KeyGeneratorTest.java b/src/test/java/org/apache/ibatis/submitted/keygen/Jdbc3KeyGeneratorTest.java index 003ef16e7b6..ddbb439d18d 100644 --- a/src/test/java/org/apache/ibatis/submitted/keygen/Jdbc3KeyGeneratorTest.java +++ b/src/test/java/org/apache/ibatis/submitted/keygen/Jdbc3KeyGeneratorTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import static com.googlecode.catchexception.apis.BDDCatchException.*; @@ -80,7 +79,6 @@ public void shouldInsertListAndRetrieveId() throws Exception { } } - @Ignore("#782 was reverted. See #902.") @Test public void shouldErrorUndefineProperty() { SqlSession sqlSession = sqlSessionFactory.openSession(); @@ -89,7 +87,7 @@ public void shouldErrorUndefineProperty() { when(mapper).insertUndefineKeyProperty(new Country("China", "CN")); then(caughtException()).isInstanceOf(PersistenceException.class).hasMessageContaining( - "### Error updating database. Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.ExecutorException: No setter found for the keyProperty 'country_id' in org.apache.ibatis.submitted.keygen.Country."); + "### Error updating database. Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.ExecutorException: No setter found for the keyProperty 'country_id' in 'org.apache.ibatis.submitted.keygen.Country'."); } finally { sqlSession.rollback(); sqlSession.close();