场景:Mybatis -- ressultMap的Collection标签使用BUG

看LOG:


===============test add!
DEBUG 12-17 18:17:08,112 ==> Preparing: select u.* , a.id as a_id ,a.contact,a.addressDesc,a.tel,a.postCode from smbms_user u,smbms_address a where u.id=a.userId and u.id=? (BaseJdbcLogger.java:145)
DEBUG 12-17 18:17:08,158 ==> Parameters: 4(Integer) (BaseJdbcLogger.java:145)
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'addressDesc' of 'class com.smbms.entities.Address' with value 'gd_sz_baoan' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'addressDesc' in 'class com.smbms.entities.Address'
### The error may exist in com/smbms/dao/UserMapper.xml
### The error may involve com.smbms.dao.UserMapper.getAddressListByUserId
### The error occurred while handling results
### SQL: select u.* , a.id as a_id ,a.contact,a.addressDesc,a.tel,a.postCode from smbms_user u,smbms_address a where u.id=a.userId and u.id=?
### Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'addressDesc' of 'class com.smbms.entities.Address' with value 'gd_sz_baoan' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'addressDesc' in 'class com.smbms.entities.Address'
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy4.getAddressListByUserId(Unknown Source)
at com.smbms.entities.UserTest.test12(UserTest.java:309)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.ibatis.reflection.ReflectionException: Could not set property 'addressDesc' of 'class com.smbms.entities.Address' with value 'gd_sz_baoan' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'addressDesc' in 'class com.smbms.entities.Address'
at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:185)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.set(BeanWrapper.java:59)
at org.apache.ibatis.reflection.MetaObject.setValue(MetaObject.java:140)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:438)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:860)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyNestedResultMappings(DefaultResultSetHandler.java:907)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:862)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForNestedResultMap(DefaultResultSetHandler.java:825)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:311)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:286)
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:183)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
... 29 more
Caused by: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'addressDesc' in 'class com.smbms.entities.Address'
at org.apache.ibatis.reflection.Reflector.getSetInvoker(Reflector.java:401)
at org.apache.ibatis.reflection.MetaClass.getSetInvoker(MetaClass.java:168)
at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:177)
... 47 more


解决:原来是定义的实体类没有给对应变量--setter方法,Mybatis的配置文件是通过访问setter方法来访问对象下的属性,所以实体类必须要有属性setter方法。

补充:

private String AddressDesc;


public String getAddressDesc() {
return AddressDesc;
}
public void setAddressDesc(String addressDesc) {
AddressDesc = addressDesc;
}