ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Priya Dani (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Created: (IBATIS-545) IBatis is not able to tackle selects with subsets of columns fetched defined in the resultMap
Date Fri, 10 Oct 2008 07:23:44 GMT
IBatis is not able to tackle selects with subsets of columns fetched defined in the resultMap

                 Key: IBATIS-545
                 URL: https://issues.apache.org/jira/browse/IBATIS-545
             Project: iBatis for Java
          Issue Type: Bug
          Components: Build/Deployment
            Reporter: Priya Dani

IBatis is not able to handle the select statements which fetch only a subset of the columns
defined in its resultMap.  I have a scenario in which the select query fetches dynamic number
of colums each time but maps to a static resultMap which contain the superset of the possible
columns that can be fetched from the query .
For eg.

 <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 

In the second query when I set the selective attribute (only cd_entity) to be fetched , a
SQL Exception is thrown saying- "Invalid column name 'nm_entity'. Check the resultMap set"
. The error occurs because in the resultMap 'EntityMap' we are using nm_entity but not really
fetching the value from select statement.

When I went through the IBatis documentation, I found one solution using "remapResults" property
with the select or statement which remaps the results if set to true everytime the query is
run. I used something like the following using IBatis version

  <select id="selectAllEntitiesCodes" resultMap="EntityMap" remapResults="true"> 
     select cd_entity from entity 

 But  this doesn't help me out with my problem. Later tried hacking the source code of IBatis
2.3.4.  What I found is the issue comes when the IBatis tries to iterate through all the properties
in the resultMap and tries to get the result from the sql resultSet passing the column name
mapped to each property in the resultMap. Obviously, it fails to get the value from the resultSet
for the columns not fetched in the select query and throws an SQL Exception. So I tried making
a small patch for it  by making a small change in the java file 'StringTypeHandler.java' like

I kept the statment inside try/catch block which fetches the specific column from the resultSet
and the function getResult() return null instead of throwing an exception.

public Object getResult(ResultSet rs, String columnName) throws SQLException	{
		Object s;
			s = rs.getString(columnName);
		catch (SQLException e)	{
			return null;
			return null;
			return s;

This small hack solved at least my purpose. I do agree this patch is not the right way to
come out of the problem since for any other reason which can throw SQLException I am catching
it out and never letting any other person know about the actual issue that causes SQL Exception
to be thrown.

Please suggest me what can be the right way to come out of this problem of using a single
resultMap for the selects which fetches dynamic number of columns.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message