Skip to content

Commit

Permalink
Throw exception when keyProperty is not found.
Browse files Browse the repository at this point in the history
Related to #782 #902 #1073.
  • Loading branch information
harawata authored and h3adache committed May 5, 2018
1 parent 57e582b commit cd35fef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.*;
Expand Down Expand Up @@ -80,7 +79,6 @@ public void shouldInsertListAndRetrieveId() throws Exception {
}
}

@Ignore("#782 was reverted. See #902.")
@Test
public void shouldErrorUndefineProperty() {
SqlSession sqlSession = sqlSessionFactory.openSession();
Expand All @@ -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();
Expand Down

0 comments on commit cd35fef

Please sign in to comment.