Second consecutive dynamic SQL incorrectly using value from first SELECT
------------------------------------------------------------------------

                 Key: IBATIS-459
                 URL: https://issues.apache.org/jira/browse/IBATIS-459
             Project: iBatis for Java
          Issue Type: Bug
          Components: SQL Maps
    Affects Versions: 2.3.0
         Environment: Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed 
mode, sharing)
ibatis-2.3.0.677.jar
mysql-connector-java-5.0.7-bin.jar
5.0.37-community-log MySQL Community Edition (GPL)
Spring Framework 2.0.1
SuSE 9.3
            Reporter: Janek Bogucki


When these two dao methods are invoked

                funDao.getUQProviderDescMostRecentDistinct("lang");
                funDao.getUQProviderDescMostRecentDistinct("pid");  <-- Throws 
exception

this exception results on the second statement:

    [junit] SqlMapClient operation; bad SQL grammar []; nested exception is 
com.ibatis.common.jdbc.exception.NestedSQLException:
    [junit] --- The error occurred in data/fun-sqlmap.xml.
    [junit] --- The error occurred while applying a result map.
    [junit] --- Check the uqProviderDescMostRecentDistinct-AutoResultMap.
    [junit] --- Check the result mapping for the 'lang' property.
    [junit] --- Cause: java.sql.SQLException: Column 'lang' not found.

Column 'lang' is not used in the underlying dynamic SQL:

    <select id="uqProviderDescMostRecentDistinct" resultClass="string" 
parameterClass="string">
        select distinct $value$ from uqProviderDesc where updateQueueId = 
(select max(id) from updateQueue) order by $value$
    </select>

The same error results without the order clause

The SQL send to MySQL is correct as can be seen from these mysql log entries

   9366                     906 Query       select distinct lang from 
uqProviderDesc where updateQueueId = (select max(id) from updateQueue) order by 
lang
   9374                     907 Query       select distinct pid from 
uqProviderDesc where updateQueueId = (select max(id) from updateQueue) order by 
pid

My DAO is based on the Spring Framework support for IBATIS,

package tests.com.studylink.data.fun;

import java.util.List;

import org.apache.commons.lang.Validate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class SqlMapFunDao extends SqlMapClientDaoSupport implements FunDao {

        public List<String> getUQProviderDescMostRecentDistinct(String field){
                Validate.notNull(field);
                return 
(List<String>)getSqlMapClientTemplate().queryForList("uqProviderDescMostRecentDistinct",
 field);
        }
}

--

When the Java statements are swapped the error message changes

                funDao.getUQProviderDescMostRecentDistinct("pid");
                funDao.getUQProviderDescMostRecentDistinct("lang");  <-- Throws 
exception

    [junit] Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
    [junit] --- The error occurred in data/fun-sqlmap.xml.
    [junit] --- The error occurred while applying a result map.
    [junit] --- Check the uqProviderDescMostRecentDistinct-AutoResultMap.
    [junit] --- Check the result mapping for the 'pid' property.
    [junit] --- Cause: java.sql.SQLException: Column 'pid' not found.



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

Reply via email to