I'm trying to re-use the same ResultMap multiple times, but in the
second query (with one column) the JDBC driver will raise an exception
because "nm_entity" does not exist in the returned ResultSet. 
        I want to avoid to define a lot of ResultMaps for the same table... Is
there an way to force IBatis to return null for missing columns instead
of raise an exception (yes, i know that is the driver that is raising
the exception because IBatis is asking for property/column
name/nm_entity) ?

        Thanks.

===========================================

Exception in thread "main"
com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in Entity.xml.  
--- The error occurred while applying a result map.  
--- Check the EntityMap.  
--- Check the result mapping for the 'name' property.  
--- Cause: org.postgresql.util.PSQLException: The column name nm_entity
was not found in this ResultSet.
        at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:201)
        at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
        at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
        at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
        at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
        at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:122)
        at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:98)
        at Test.main(Test.java:23)


On Thu, 2008-09-25 at 14:05 -0500, Shannon, Bryan wrote:
> You can alias your columns in your select.
> 
> 
>  Select foo as cd_entity, bar as nm_entity from table
> 
> iBatis will use the alias to map the results in the resultMap.
> 
> -----Original Message-----
> From: Daniel Henrique Alves Lima [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, September 25, 2008 2:32 PM
> To: [email protected]
> Subject: ResultMap columns as a superset of select columns
> 
>       Hi everybody. First of all: I'm sorry for my bad English.
> 
>       How can define just one resultMap with all necessary columns and
> reuse it in selects with different columns ?
>       Something like this:
> 
>    <resultMap id="EntityMap" class="Entity">
>      <result property="code" column="cd_entity" />
>      <result property="name" column="nm_entity" />
>    </resultMap>
> 
>    <select id="selectAllEntities" resultMap="EntityMap">
>      select * from entity
>    </select>
> 
>    <select id="selectAllEntitiesCodes" resultMap="EntityMap">
>      select cd_entity from entity
>    </select>
> 
> 
>       Can I implement/extend some of the IBatis' interfaces and
> classes to achieve this ?
> 
> 
>       Thanks in advance !
> 
> 
-- 
"If there must be trouble, let it be in my day, 
 that my child may have peace."

Thomas Paine

Reply via email to