ibatis一个很不灵活的地方

最近一直都不爽ibtais,用起来一点都不敏捷。今天发现一处非常不灵活的地方。比如一个DO我有两条SQL,其中一条SQL比另外一条SQL多一个last_like_datetime。我想共用一个resultMap居然会报错:

 

	   <resultMap id="RM-ALBUM" class="TA-ALBUM">
        	<result property="id" 				column="id"/>
        	<result property="gmtCreate" 		column="create_datetime"/>
        	<result property="lastLikeDatetime" 		column="last_like_datetime"/>
       </resultMap>

 

 

 

Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in com/duitang/model/mysql/blog/AlbumDO.xml.  
--- The error occurred while applying a result map.  
--- Check the AlbumDO.RM-ALBUM.  
--- Check the result mapping for the 'lastLikeDatetime' property.  
--- Cause: java.sql.SQLException: Column 'last_like_datetime' not found.
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
	at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
	at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
	at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
	at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:270)
	at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
	... 32 more
Caused by: java.sql.SQLException: Column 'last_like_datetime' not found.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
	at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1166)
	at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:6229)
	at org.apache.commons.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:300)
	at org.apache.commons.dbcp.DelegatingResultSet.getTimestamp(DelegatingResultSet.java:300)
	at com.ibatis.sqlmap.engine.type.DateTypeHandler.getResult(DateTypeHandler.java:38)
	at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getPrimitiveResultMappingValue(ResultMap.java:619)
	at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:345)
	at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
	at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
	at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
	at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
	... 38 more

 原来这SB只要发现resultMap有定义字段就会直接调用rs.getResult('column_name')。

 

你可能感兴趣的:(ibatis)