You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Dimiter Kapitanov (JIRA)" <ib...@incubator.apache.org> on 2005/01/18 15:46:17 UTC

[jira] Created: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Nulls interpretted incorrectly in version 2.0.9
-----------------------------------------------

         Key: IBATIS-51
         URL: http://issues.apache.org/jira/browse/IBATIS-51
     Project: iBatis for Java
        Type: Bug
  Components: SQL Maps  
    Versions: 2.0.9    
 Environment: MySQL 3.23.x
    Reporter: Dimiter Kapitanov


When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
Demonstration code :

-------------------------
[M.java]

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.io.*;
import java.util.*;

/**
 * Test for bug in iBatis DBL 2.0.9.
 */
public class M
{
    public static void main(String[] args)
    {
        System.out.println("Testing iBatis DBL 2.0.9 bug : ");
        System.out.println("If you run this program with iBatis 2.0.7 it " +
            "will return result, if you run it with iBatis 2.0.9 it will " +
            "return null.");
        
        try
        {
            String mapFile = "DB_Config.xml";
            Reader reader = new FileReader(mapFile);
            SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
                reader);
            
            HashMap m = new HashMap();
            m.put("name", "Am");
            Map result = (Map)mapper.queryForObject("selectAccount", m);
            
            System.out.println("Result = " + result);
        }
        catch (Exception exc)
        {
            exc.printStackTrace(); 
        }
    }
} 

-------------------------
[DB_Config.xml]

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">

<sqlMapConfig>

  <properties resource="debug.ini"/>

  <transactionManager type="JDBC">
    <dataSource type="SIMPLE">
      <property value="${DB_DRIVER}" name="JDBC.Driver"/>
      <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
      <property value="${DB_USER}" name="JDBC.Username"/>
      <property value="${DB_PASSWORD}" name="JDBC.Password"/>
      <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
      <property value="15" name="Pool.MaximumActiveConnections"/>
      <property value="15" name="Pool.MaximumIdleConnections"/>
      <property value="1000" name="Pool.MaximumWait"/>
    </dataSource>
  </transactionManager>

  <sqlMap resource="Account.xml"/>
  
</sqlMapConfig>

-------------------------
[Account.xml]

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
 "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap>
    <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        SELECT * FROM table1
        <dynamic prepend="WHERE">
        <isPropertyAvailable prepend="AND" property="id">
            id = #id#
        </isPropertyAvailable>
        <isPropertyAvailable prepend="AND" property="name">
            name = #name#
        </isPropertyAvailable>
        </dynamic>
        ORDER BY name
    </statement>
</sqlMap>

---------------------
[debug.sql]

#
# testDB SQL script (uses MySQL 3.23.x).
#

CREATE DATABASE testDB;

GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
FLUSH PRIVILEGES;

use testDB;

CREATE TABLE table1 (
  id int unsigned NOT NULL auto_increment primary key,
  name varchar(20)
);

insert into table1 values (1, 'Am');
insert into table1 values (2, 'Tam');

---------------------
[debug.ini]

# 
# testDB settings.
#

DB_DRIVER=com.mysql.jdbc.Driver
DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
DB_USER=testDB
DB_PASSWORD=testDB
DB_QUERY=select 1 from table1



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


Re: [jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by Brandon Goodin <br...@gmail.com>.
I agree with Dimiter. If you are using maps you should ensure that it
contains all the properties/keys to satisfy your needs. It seems to me
that it is their choice to use maps (which is a REALLY REALLY REALLY
bad idea) and it then becomes their responsibility to make sure the
map has the keys. If you fail to place the appropriate keys in the map
it should stand that you are using the map improperly. I think it is
important for us to maintain behavior similar between beans and maps
(as much as is possible).

As a parting shot... you guys should NOT be using maps as extensively
as you are. They were meant to be an exception NOT a rule.

Brandon



On Tue, 8 Feb 2005 11:06:12 +0100 (CET), Dimiter Kapitanov (JIRA)
<ib...@incubator.apache.org> wrote:
>      [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58749 ]
> 
> Dimiter Kapitanov commented on IBATIS-51:
> -----------------------------------------
> 
> Hello Clinton.
> Thank you for your reply. I understand what you meen, but let me explain the other point of view.
> We have a project with HUGE domain model. We use Map as replacement of all java-beans (yes I am serious). iBatis is perfect for this, because it doesn't force us to use 'classic-only' things.
> Imagine this 3 possible cases :
> 
> 1) parameterClass : Map[key1=value1]
> iBatis : insert/update field 'key1' to new value.
> 
> 2) parameterClass : Map[key1=null]
> iBatis : clear the value of 'key1'.
> 
> 3) parameterClass : Map[key2=value2] (no property 'key1')
> iBatis : keep 'key1' as is, but update 'key2'.
> 
> If <isPropertyAvailable> works differently for Maps and JavaBeans properties, we cannot distinguish case 2) and 3). Even <isNotNull> cannot help us in this case.
> Please, consider again 'isPropertyAvailable' behaviour - for all these who use Maps.
> 
> All the best,
> Dimiter
> 
> > Nulls interpretted incorrectly in version 2.0.9
> > -----------------------------------------------
> >
> >          Key: IBATIS-51
> >          URL: http://issues.apache.org/jira/browse/IBATIS-51
> >      Project: iBatis for Java
> >         Type: Bug
> >   Components: SQL Maps
> >     Versions: 2.0.9
> >  Environment: MySQL 3.23.x
> >     Reporter: Dimiter Kapitanov
> 
> >
> > When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> > This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> > Demonstration code :
> > -------------------------
> > [M.java]
> > import com.ibatis.sqlmap.client.SqlMapClient;
> > import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> > import java.io.*;
> > import java.util.*;
> > /**
> >  * Test for bug in iBatis DBL 2.0.9.
> >  */
> > public class M
> > {
> >     public static void main(String[] args)
> >     {
> >         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
> >         System.out.println("If you run this program with iBatis 2.0.7 it " +
> >             "will return result, if you run it with iBatis 2.0.9 it will " +
> >             "return null.");
> >
> >         try
> >         {
> >             String mapFile = "DB_Config.xml";
> >             Reader reader = new FileReader(mapFile);
> >             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
> >                 reader);
> >
> >             HashMap m = new HashMap();
> >             m.put("name", "Am");
> >             Map result = (Map)mapper.queryForObject("selectAccount", m);
> >
> >             System.out.println("Result = " + result);
> >         }
> >         catch (Exception exc)
> >         {
> >             exc.printStackTrace();
> >         }
> >     }
> > }
> > -------------------------
> > [DB_Config.xml]
> > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> > <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> > <sqlMapConfig>
> >   <properties resource="debug.ini"/>
> >   <transactionManager type="JDBC">
> >     <dataSource type="SIMPLE">
> >       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
> >       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
> >       <property value="${DB_USER}" name="JDBC.Username"/>
> >       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
> >       <property value="${DB_QUERY}" name="Pool.PingQuery"/>
> >       <property value="15" name="Pool.MaximumActiveConnections"/>
> >       <property value="15" name="Pool.MaximumIdleConnections"/>
> >       <property value="1000" name="Pool.MaximumWait"/>
> >     </dataSource>
> >   </transactionManager>
> >   <sqlMap resource="Account.xml"/>
> >
> > </sqlMapConfig>
> > -------------------------
> > [Account.xml]
> > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> > <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
> >  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> > <sqlMap>
> >     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
> >         SELECT * FROM table1
> >         <dynamic prepend="WHERE">
> >         <isPropertyAvailable prepend="AND" property="id">
> >             id = #id#
> >         </isPropertyAvailable>
> >         <isPropertyAvailable prepend="AND" property="name">
> >             name = #name#
> >         </isPropertyAvailable>
> >         </dynamic>
> >         ORDER BY name
> >     </statement>
> > </sqlMap>
> > ---------------------
> > [debug.sql]
> > #
> > # testDB SQL script (uses MySQL 3.23.x).
> > #
> > CREATE DATABASE testDB;
> > GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> > FLUSH PRIVILEGES;
> > use testDB;
> > CREATE TABLE table1 (
> >   id int unsigned NOT NULL auto_increment primary key,
> >   name varchar(20)
> > );
> > insert into table1 values (1, 'Am');
> > insert into table1 values (2, 'Tam');
> > ---------------------
> > [debug.ini]
> > #
> > # testDB settings.
> > #
> > DB_DRIVER=com.mysql.jdbc.Driver
> > DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> > DB_USER=testDB
> > DB_PASSWORD=testDB
> > DB_QUERY=select 1 from table1
> 
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
>    http://issues.apache.org/jira/secure/Administrators.jspa
> -
> If you want more information on JIRA, or have a bug to report see:
>    http://www.atlassian.com/software/jira
> 
>

Re: [jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by Clinton Begin <cl...@gmail.com>.
Agreed. (about the "blargh" part, not the property part)  ;-)

As much as possible, my personal preference is to have iBATIS work one
way (no pun intended).  The fewer global, framework mutilating
properties that we have, the better.

Consistency is of critical importance.  We're not perfect yet, but
it's hard with Maps, XML and Beans.

Cheers,
Clinton


On Mon, 7 Feb 2005 09:35:32 -0700, Brandon Goodin
<br...@gmail.com> wrote:
> What if we introduced a configuration element
> 'explicitMap="(true|false)"' If it's true you will need to define a
> key for every property. If it is false it will function like it
> currently does. This  could be  global attribute. Of course this could
> lead us to more people wanting finer grained configuration
> functionality for maps (blargh!!!!).
> 
> Brandon
> 
> On Mon, 7 Feb 2005 17:30:12 +0100 (CET), Clinton Begin (JIRA)
> <ib...@incubator.apache.org> wrote:
> >      [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58679 ]
> >
> > Clinton Begin commented on IBATIS-51:
> > -------------------------------------
> >
> > Thanks for figuring this one out Dimiter.
> >
> > This was a concious decision made by us.  Previously a bug was entered that made sense...as you can see I've always been uncomfortable with the subject, as I even left the old code there.
> >
> > So, here's a perfect example of why Maps suck for domain models (not a criticism, just a point).  When exactly does a Map "have" a property?  There are two possibilities:
> >
> > 1) A Map has properties based on whether it "containsKey" for the given property name.
> >     - Caveat:  In some cases you'll find yourself having to set keys in the Map before they'll work with a given statement as a parameter or predefined result.  Perhaps this is better, simply because it is more explicit.
> >
> > -OR-
> >
> > 2) Because a Map is so loosely described, a Map can be said to have ANY property --all the time, no matter what keys are currently on it.
> >     - Caveat: <isPropertyAvailable>  will always return true.
> >
> > So before I swing the pendulum back towards option #1, I wonder if you guys can possibly use <isNotNull> instead of <isPresent>?
> >
> > PS:  It's not so much that we're busy, but in fact our source tree has been locked for two weeks in transition to ASF infrastructure....sad but true.
> >
> > Cheers,
> > Clinton
> >
> > > Nulls interpretted incorrectly in version 2.0.9
> > > -----------------------------------------------
> > >
> > >          Key: IBATIS-51
> > >          URL: http://issues.apache.org/jira/browse/IBATIS-51
> > >      Project: iBatis for Java
> > >         Type: Bug
> > >   Components: SQL Maps
> > >     Versions: 2.0.9
> > >  Environment: MySQL 3.23.x
> > >     Reporter: Dimiter Kapitanov
> >
> > >
> > > When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> > > This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> > > Demonstration code :
> > > -------------------------
> > > [M.java]
> > > import com.ibatis.sqlmap.client.SqlMapClient;
> > > import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> > > import java.io.*;
> > > import java.util.*;
> > > /**
> > >  * Test for bug in iBatis DBL 2.0.9.
> > >  */
> > > public class M
> > > {
> > >     public static void main(String[] args)
> > >     {
> > >         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
> > >         System.out.println("If you run this program with iBatis 2.0.7 it " +
> > >             "will return result, if you run it with iBatis 2.0.9 it will " +
> > >             "return null.");
> > >
> > >         try
> > >         {
> > >             String mapFile = "DB_Config.xml";
> > >             Reader reader = new FileReader(mapFile);
> > >             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
> > >                 reader);
> > >
> > >             HashMap m = new HashMap();
> > >             m.put("name", "Am");
> > >             Map result = (Map)mapper.queryForObject("selectAccount", m);
> > >
> > >             System.out.println("Result = " + result);
> > >         }
> > >         catch (Exception exc)
> > >         {
> > >             exc.printStackTrace();
> > >         }
> > >     }
> > > }
> > > -------------------------
> > > [DB_Config.xml]
> > > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> > > <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> > > <sqlMapConfig>
> > >   <properties resource="debug.ini"/>
> > >   <transactionManager type="JDBC">
> > >     <dataSource type="SIMPLE">
> > >       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
> > >       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
> > >       <property value="${DB_USER}" name="JDBC.Username"/>
> > >       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
> > >       <property value="${DB_QUERY}" name="Pool.PingQuery"/>
> > >       <property value="15" name="Pool.MaximumActiveConnections"/>
> > >       <property value="15" name="Pool.MaximumIdleConnections"/>
> > >       <property value="1000" name="Pool.MaximumWait"/>
> > >     </dataSource>
> > >   </transactionManager>
> > >   <sqlMap resource="Account.xml"/>
> > >
> > > </sqlMapConfig>
> > > -------------------------
> > > [Account.xml]
> > > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> > > <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
> > >  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> > > <sqlMap>
> > >     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
> > >         SELECT * FROM table1
> > >         <dynamic prepend="WHERE">
> > >         <isPropertyAvailable prepend="AND" property="id">
> > >             id = #id#
> > >         </isPropertyAvailable>
> > >         <isPropertyAvailable prepend="AND" property="name">
> > >             name = #name#
> > >         </isPropertyAvailable>
> > >         </dynamic>
> > >         ORDER BY name
> > >     </statement>
> > > </sqlMap>
> > > ---------------------
> > > [debug.sql]
> > > #
> > > # testDB SQL script (uses MySQL 3.23.x).
> > > #
> > > CREATE DATABASE testDB;
> > > GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> > > FLUSH PRIVILEGES;
> > > use testDB;
> > > CREATE TABLE table1 (
> > >   id int unsigned NOT NULL auto_increment primary key,
> > >   name varchar(20)
> > > );
> > > insert into table1 values (1, 'Am');
> > > insert into table1 values (2, 'Tam');
> > > ---------------------
> > > [debug.ini]
> > > #
> > > # testDB settings.
> > > #
> > > DB_DRIVER=com.mysql.jdbc.Driver
> > > DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> > > DB_USER=testDB
> > > DB_PASSWORD=testDB
> > > DB_QUERY=select 1 from table1
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > If you think it was sent incorrectly contact one of the administrators:
> >    http://issues.apache.org/jira/secure/Administrators.jspa
> > -
> > If you want more information on JIRA, or have a bug to report see:
> >    http://www.atlassian.com/software/jira
> >
> >
>

Re: [jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by Brandon Goodin <br...@gmail.com>.
What if we introduced a configuration element
'explicitMap="(true|false)"' If it's true you will need to define a
key for every property. If it is false it will function like it
currently does. This  could be  global attribute. Of course this could
lead us to more people wanting finer grained configuration
functionality for maps (blargh!!!!).

Brandon


On Mon, 7 Feb 2005 17:30:12 +0100 (CET), Clinton Begin (JIRA)
<ib...@incubator.apache.org> wrote:
>      [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58679 ]
> 
> Clinton Begin commented on IBATIS-51:
> -------------------------------------
> 
> Thanks for figuring this one out Dimiter.
> 
> This was a concious decision made by us.  Previously a bug was entered that made sense...as you can see I've always been uncomfortable with the subject, as I even left the old code there.
> 
> So, here's a perfect example of why Maps suck for domain models (not a criticism, just a point).  When exactly does a Map "have" a property?  There are two possibilities:
> 
> 1) A Map has properties based on whether it "containsKey" for the given property name.
>     - Caveat:  In some cases you'll find yourself having to set keys in the Map before they'll work with a given statement as a parameter or predefined result.  Perhaps this is better, simply because it is more explicit.
> 
> -OR-
> 
> 2) Because a Map is so loosely described, a Map can be said to have ANY property --all the time, no matter what keys are currently on it.
>     - Caveat: <isPropertyAvailable>  will always return true.
> 
> So before I swing the pendulum back towards option #1, I wonder if you guys can possibly use <isNotNull> instead of <isPresent>?
> 
> PS:  It's not so much that we're busy, but in fact our source tree has been locked for two weeks in transition to ASF infrastructure....sad but true.
> 
> Cheers,
> Clinton
> 
> > Nulls interpretted incorrectly in version 2.0.9
> > -----------------------------------------------
> >
> >          Key: IBATIS-51
> >          URL: http://issues.apache.org/jira/browse/IBATIS-51
> >      Project: iBatis for Java
> >         Type: Bug
> >   Components: SQL Maps
> >     Versions: 2.0.9
> >  Environment: MySQL 3.23.x
> >     Reporter: Dimiter Kapitanov
> 
> >
> > When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> > This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> > Demonstration code :
> > -------------------------
> > [M.java]
> > import com.ibatis.sqlmap.client.SqlMapClient;
> > import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> > import java.io.*;
> > import java.util.*;
> > /**
> >  * Test for bug in iBatis DBL 2.0.9.
> >  */
> > public class M
> > {
> >     public static void main(String[] args)
> >     {
> >         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
> >         System.out.println("If you run this program with iBatis 2.0.7 it " +
> >             "will return result, if you run it with iBatis 2.0.9 it will " +
> >             "return null.");
> >
> >         try
> >         {
> >             String mapFile = "DB_Config.xml";
> >             Reader reader = new FileReader(mapFile);
> >             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
> >                 reader);
> >
> >             HashMap m = new HashMap();
> >             m.put("name", "Am");
> >             Map result = (Map)mapper.queryForObject("selectAccount", m);
> >
> >             System.out.println("Result = " + result);
> >         }
> >         catch (Exception exc)
> >         {
> >             exc.printStackTrace();
> >         }
> >     }
> > }
> > -------------------------
> > [DB_Config.xml]
> > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> > <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> > <sqlMapConfig>
> >   <properties resource="debug.ini"/>
> >   <transactionManager type="JDBC">
> >     <dataSource type="SIMPLE">
> >       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
> >       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
> >       <property value="${DB_USER}" name="JDBC.Username"/>
> >       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
> >       <property value="${DB_QUERY}" name="Pool.PingQuery"/>
> >       <property value="15" name="Pool.MaximumActiveConnections"/>
> >       <property value="15" name="Pool.MaximumIdleConnections"/>
> >       <property value="1000" name="Pool.MaximumWait"/>
> >     </dataSource>
> >   </transactionManager>
> >   <sqlMap resource="Account.xml"/>
> >
> > </sqlMapConfig>
> > -------------------------
> > [Account.xml]
> > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> > <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
> >  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> > <sqlMap>
> >     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
> >         SELECT * FROM table1
> >         <dynamic prepend="WHERE">
> >         <isPropertyAvailable prepend="AND" property="id">
> >             id = #id#
> >         </isPropertyAvailable>
> >         <isPropertyAvailable prepend="AND" property="name">
> >             name = #name#
> >         </isPropertyAvailable>
> >         </dynamic>
> >         ORDER BY name
> >     </statement>
> > </sqlMap>
> > ---------------------
> > [debug.sql]
> > #
> > # testDB SQL script (uses MySQL 3.23.x).
> > #
> > CREATE DATABASE testDB;
> > GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> > FLUSH PRIVILEGES;
> > use testDB;
> > CREATE TABLE table1 (
> >   id int unsigned NOT NULL auto_increment primary key,
> >   name varchar(20)
> > );
> > insert into table1 values (1, 'Am');
> > insert into table1 values (2, 'Tam');
> > ---------------------
> > [debug.ini]
> > #
> > # testDB settings.
> > #
> > DB_DRIVER=com.mysql.jdbc.Driver
> > DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> > DB_USER=testDB
> > DB_PASSWORD=testDB
> > DB_QUERY=select 1 from table1
> 
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
>    http://issues.apache.org/jira/secure/Administrators.jspa
> -
> If you want more information on JIRA, or have a bug to report see:
>    http://www.atlassian.com/software/jira
> 
>

Re: [jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by Philippe Laflamme <ph...@mail.mcgill.ca>.
 > So, would <isNotNull> work for you instead?

Yep, that's fine for our situation.

 > Your point is well taken, but I'd place that issue on the
 > <isPropertyAvailable> tag (and it's uselessness), not necessarily on
 > the Map introspection support.

Both are related. The uselessness of isPropertyAvailable tag comes from 
the desicions made for Map introspection. If the "pendulum" swings by 
option #1, it's still useful (when dealing with Map parameterClasses).

I guess a new issue about the tag could depend on this one (#51). What 
do you think?

Philippe

Clinton Begin wrote:
> The <isPropertyAvailable> tag was intended for loosely defined
> parameter classes.  Perhaps it's not very usefull anymore, now that
> parameter maps are pretty much concretely tied to the statement.  In
> version 1.x, you could pass different parameter types to the
> statements that would be dynamically resolved at runtime.  So
> isPropertyAvailable could be used in those cases.
> 
> Your point is well taken, but I'd place that issue on the
> <isPropertyAvailable> tag (and it's uselessness), not necessarily on
> the Map introspection support.
> 
> So, would <isNotNull> work for you instead?
> 
> Cheers,
> Clinton
> 
> 
> On Mon, 07 Feb 2005 11:54:50 -0500, Philippe Laflamme
> <ph...@mail.mcgill.ca> wrote:
> 
>>I wonder what the use of the <isPropertyAvailable> can be if it's not
>>applied to a Map (before 2.0.8). You cannot change a statement's
>>parameter map dynamically (one statement, one parameter map/class), so
>>the properties that are available when building the statement cannot
>>change. If I'm not mistaken, the answer to isPropertyAvailable is
>>_always_ the same (true or false), no matter how you're calling a
>>statement. I'm probably overlooking something...
>>
>>We use the isPropertyAvailable tag in certain rare situations, but only
>>when dealing with paramater classes that are Maps. How is the tag useful
>>when dealing with a bean?
>>
>>Thanks,
>>Philippe
>>
>>
>>Clinton Begin (JIRA) wrote:
>>
>>>     [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58679 ]
>>>
>>>Clinton Begin commented on IBATIS-51:
>>>-------------------------------------
>>>
>>>Thanks for figuring this one out Dimiter.
>>>
>>>This was a concious decision made by us.  Previously a bug was entered that made sense...as you can see I've always been uncomfortable with the subject, as I even left the old code there.
>>>
>>>So, here's a perfect example of why Maps suck for domain models (not a criticism, just a point).  When exactly does a Map "have" a property?  There are two possibilities:
>>>
>>>1) A Map has properties based on whether it "containsKey" for the given property name.
>>>    - Caveat:  In some cases you'll find yourself having to set keys in the Map before they'll work with a given statement as a parameter or predefined result.  Perhaps this is better, simply because it is more explicit.
>>>
>>>-OR-
>>>
>>>2) Because a Map is so loosely described, a Map can be said to have ANY property --all the time, no matter what keys are currently on it.
>>>    - Caveat: <isPropertyAvailable>  will always return true.
>>>
>>>So before I swing the pendulum back towards option #1, I wonder if you guys can possibly use <isNotNull> instead of <isPresent>?
>>>
>>>PS:  It's not so much that we're busy, but in fact our source tree has been locked for two weeks in transition to ASF infrastructure....sad but true.
>>>
>>>Cheers,
>>>Clinton
>>>
>>>
>>>
>>>>Nulls interpretted incorrectly in version 2.0.9
>>>>-----------------------------------------------
>>>>
>>>>        Key: IBATIS-51
>>>>        URL: http://issues.apache.org/jira/browse/IBATIS-51
>>>>    Project: iBatis for Java
>>>>       Type: Bug
>>>> Components: SQL Maps
>>>>   Versions: 2.0.9
>>>>Environment: MySQL 3.23.x
>>>>   Reporter: Dimiter Kapitanov
>>>
>>>
>>>>When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
>>>>This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
>>>>Demonstration code :
>>>>-------------------------
>>>>[M.java]
>>>>import com.ibatis.sqlmap.client.SqlMapClient;
>>>>import com.ibatis.sqlmap.client.SqlMapClientBuilder;
>>>>import java.io.*;
>>>>import java.util.*;
>>>>/**
>>>>* Test for bug in iBatis DBL 2.0.9.
>>>>*/
>>>>public class M
>>>>{
>>>>   public static void main(String[] args)
>>>>   {
>>>>       System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>>>>       System.out.println("If you run this program with iBatis 2.0.7 it " +
>>>>           "will return result, if you run it with iBatis 2.0.9 it will " +
>>>>           "return null.");
>>>>
>>>>       try
>>>>       {
>>>>           String mapFile = "DB_Config.xml";
>>>>           Reader reader = new FileReader(mapFile);
>>>>           SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>>>>               reader);
>>>>
>>>>           HashMap m = new HashMap();
>>>>           m.put("name", "Am");
>>>>           Map result = (Map)mapper.queryForObject("selectAccount", m);
>>>>
>>>>           System.out.println("Result = " + result);
>>>>       }
>>>>       catch (Exception exc)
>>>>       {
>>>>           exc.printStackTrace();
>>>>       }
>>>>   }
>>>>}
>>>>-------------------------
>>>>[DB_Config.xml]
>>>><?xml version="1.0" encoding="UTF-8" standalone="no"?>
>>>><!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
>>>><sqlMapConfig>
>>>> <properties resource="debug.ini"/>
>>>> <transactionManager type="JDBC">
>>>>   <dataSource type="SIMPLE">
>>>>     <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>>>>     <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>>>>     <property value="${DB_USER}" name="JDBC.Username"/>
>>>>     <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>>>>     <property value="${DB_QUERY}" name="Pool.PingQuery"/>
>>>>     <property value="15" name="Pool.MaximumActiveConnections"/>
>>>>     <property value="15" name="Pool.MaximumIdleConnections"/>
>>>>     <property value="1000" name="Pool.MaximumWait"/>
>>>>   </dataSource>
>>>> </transactionManager>
>>>> <sqlMap resource="Account.xml"/>
>>>>
>>>></sqlMapConfig>
>>>>-------------------------
>>>>[Account.xml]
>>>><?xml version="1.0" encoding="UTF-8" standalone="no"?>
>>>><!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
>>>>"http://www.ibatis.com/dtd/sql-map-2.dtd">
>>>><sqlMap>
>>>>   <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>>>>       SELECT * FROM table1
>>>>       <dynamic prepend="WHERE">
>>>>       <isPropertyAvailable prepend="AND" property="id">
>>>>           id = #id#
>>>>       </isPropertyAvailable>
>>>>       <isPropertyAvailable prepend="AND" property="name">
>>>>           name = #name#
>>>>       </isPropertyAvailable>
>>>>       </dynamic>
>>>>       ORDER BY name
>>>>   </statement>
>>>></sqlMap>
>>>>---------------------
>>>>[debug.sql]
>>>>#
>>>># testDB SQL script (uses MySQL 3.23.x).
>>>>#
>>>>CREATE DATABASE testDB;
>>>>GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
>>>>FLUSH PRIVILEGES;
>>>>use testDB;
>>>>CREATE TABLE table1 (
>>>> id int unsigned NOT NULL auto_increment primary key,
>>>> name varchar(20)
>>>>);
>>>>insert into table1 values (1, 'Am');
>>>>insert into table1 values (2, 'Tam');
>>>>---------------------
>>>>[debug.ini]
>>>>#
>>>># testDB settings.
>>>>#
>>>>DB_DRIVER=com.mysql.jdbc.Driver
>>>>DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
>>>>DB_USER=testDB
>>>>DB_PASSWORD=testDB
>>>>DB_QUERY=select 1 from table1
>>>
>>>
>>
> 


Re: [jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by Clinton Begin <cl...@gmail.com>.
The <isPropertyAvailable> tag was intended for loosely defined
parameter classes.  Perhaps it's not very usefull anymore, now that
parameter maps are pretty much concretely tied to the statement.  In
version 1.x, you could pass different parameter types to the
statements that would be dynamically resolved at runtime.  So
isPropertyAvailable could be used in those cases.

Your point is well taken, but I'd place that issue on the
<isPropertyAvailable> tag (and it's uselessness), not necessarily on
the Map introspection support.

So, would <isNotNull> work for you instead?

Cheers,
Clinton


On Mon, 07 Feb 2005 11:54:50 -0500, Philippe Laflamme
<ph...@mail.mcgill.ca> wrote:
> 
> I wonder what the use of the <isPropertyAvailable> can be if it's not
> applied to a Map (before 2.0.8). You cannot change a statement's
> parameter map dynamically (one statement, one parameter map/class), so
> the properties that are available when building the statement cannot
> change. If I'm not mistaken, the answer to isPropertyAvailable is
> _always_ the same (true or false), no matter how you're calling a
> statement. I'm probably overlooking something...
> 
> We use the isPropertyAvailable tag in certain rare situations, but only
> when dealing with paramater classes that are Maps. How is the tag useful
> when dealing with a bean?
> 
> Thanks,
> Philippe
> 
> 
> Clinton Begin (JIRA) wrote:
> >      [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58679 ]
> >
> > Clinton Begin commented on IBATIS-51:
> > -------------------------------------
> >
> > Thanks for figuring this one out Dimiter.
> >
> > This was a concious decision made by us.  Previously a bug was entered that made sense...as you can see I've always been uncomfortable with the subject, as I even left the old code there.
> >
> > So, here's a perfect example of why Maps suck for domain models (not a criticism, just a point).  When exactly does a Map "have" a property?  There are two possibilities:
> >
> > 1) A Map has properties based on whether it "containsKey" for the given property name.
> >     - Caveat:  In some cases you'll find yourself having to set keys in the Map before they'll work with a given statement as a parameter or predefined result.  Perhaps this is better, simply because it is more explicit.
> >
> > -OR-
> >
> > 2) Because a Map is so loosely described, a Map can be said to have ANY property --all the time, no matter what keys are currently on it.
> >     - Caveat: <isPropertyAvailable>  will always return true.
> >
> > So before I swing the pendulum back towards option #1, I wonder if you guys can possibly use <isNotNull> instead of <isPresent>?
> >
> > PS:  It's not so much that we're busy, but in fact our source tree has been locked for two weeks in transition to ASF infrastructure....sad but true.
> >
> > Cheers,
> > Clinton
> >
> >
> >>Nulls interpretted incorrectly in version 2.0.9
> >>-----------------------------------------------
> >>
> >>         Key: IBATIS-51
> >>         URL: http://issues.apache.org/jira/browse/IBATIS-51
> >>     Project: iBatis for Java
> >>        Type: Bug
> >>  Components: SQL Maps
> >>    Versions: 2.0.9
> >> Environment: MySQL 3.23.x
> >>    Reporter: Dimiter Kapitanov
> >
> >
> >>When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> >>This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> >>Demonstration code :
> >>-------------------------
> >>[M.java]
> >>import com.ibatis.sqlmap.client.SqlMapClient;
> >>import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> >>import java.io.*;
> >>import java.util.*;
> >>/**
> >> * Test for bug in iBatis DBL 2.0.9.
> >> */
> >>public class M
> >>{
> >>    public static void main(String[] args)
> >>    {
> >>        System.out.println("Testing iBatis DBL 2.0.9 bug : ");
> >>        System.out.println("If you run this program with iBatis 2.0.7 it " +
> >>            "will return result, if you run it with iBatis 2.0.9 it will " +
> >>            "return null.");
> >>
> >>        try
> >>        {
> >>            String mapFile = "DB_Config.xml";
> >>            Reader reader = new FileReader(mapFile);
> >>            SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
> >>                reader);
> >>
> >>            HashMap m = new HashMap();
> >>            m.put("name", "Am");
> >>            Map result = (Map)mapper.queryForObject("selectAccount", m);
> >>
> >>            System.out.println("Result = " + result);
> >>        }
> >>        catch (Exception exc)
> >>        {
> >>            exc.printStackTrace();
> >>        }
> >>    }
> >>}
> >>-------------------------
> >>[DB_Config.xml]
> >><?xml version="1.0" encoding="UTF-8" standalone="no"?>
> >><!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> >><sqlMapConfig>
> >>  <properties resource="debug.ini"/>
> >>  <transactionManager type="JDBC">
> >>    <dataSource type="SIMPLE">
> >>      <property value="${DB_DRIVER}" name="JDBC.Driver"/>
> >>      <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
> >>      <property value="${DB_USER}" name="JDBC.Username"/>
> >>      <property value="${DB_PASSWORD}" name="JDBC.Password"/>
> >>      <property value="${DB_QUERY}" name="Pool.PingQuery"/>
> >>      <property value="15" name="Pool.MaximumActiveConnections"/>
> >>      <property value="15" name="Pool.MaximumIdleConnections"/>
> >>      <property value="1000" name="Pool.MaximumWait"/>
> >>    </dataSource>
> >>  </transactionManager>
> >>  <sqlMap resource="Account.xml"/>
> >>
> >></sqlMapConfig>
> >>-------------------------
> >>[Account.xml]
> >><?xml version="1.0" encoding="UTF-8" standalone="no"?>
> >><!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"
> >> "http://www.ibatis.com/dtd/sql-map-2.dtd">
> >><sqlMap>
> >>    <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
> >>        SELECT * FROM table1
> >>        <dynamic prepend="WHERE">
> >>        <isPropertyAvailable prepend="AND" property="id">
> >>            id = #id#
> >>        </isPropertyAvailable>
> >>        <isPropertyAvailable prepend="AND" property="name">
> >>            name = #name#
> >>        </isPropertyAvailable>
> >>        </dynamic>
> >>        ORDER BY name
> >>    </statement>
> >></sqlMap>
> >>---------------------
> >>[debug.sql]
> >>#
> >># testDB SQL script (uses MySQL 3.23.x).
> >>#
> >>CREATE DATABASE testDB;
> >>GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> >>FLUSH PRIVILEGES;
> >>use testDB;
> >>CREATE TABLE table1 (
> >>  id int unsigned NOT NULL auto_increment primary key,
> >>  name varchar(20)
> >>);
> >>insert into table1 values (1, 'Am');
> >>insert into table1 values (2, 'Tam');
> >>---------------------
> >>[debug.ini]
> >>#
> >># testDB settings.
> >>#
> >>DB_DRIVER=com.mysql.jdbc.Driver
> >>DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> >>DB_USER=testDB
> >>DB_PASSWORD=testDB
> >>DB_QUERY=select 1 from table1
> >
> >
> 
>

Re: [jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by Philippe Laflamme <ph...@mail.mcgill.ca>.
I wonder what the use of the <isPropertyAvailable> can be if it's not 
applied to a Map (before 2.0.8). You cannot change a statement's 
parameter map dynamically (one statement, one parameter map/class), so 
the properties that are available when building the statement cannot 
change. If I'm not mistaken, the answer to isPropertyAvailable is 
_always_ the same (true or false), no matter how you're calling a 
statement. I'm probably overlooking something...

We use the isPropertyAvailable tag in certain rare situations, but only 
when dealing with paramater classes that are Maps. How is the tag useful 
when dealing with a bean?

Thanks,
Philippe


Clinton Begin (JIRA) wrote:
>      [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58679 ]
>      
> Clinton Begin commented on IBATIS-51:
> -------------------------------------
> 
> Thanks for figuring this one out Dimiter.
> 
> This was a concious decision made by us.  Previously a bug was entered that made sense...as you can see I've always been uncomfortable with the subject, as I even left the old code there. 
> 
> So, here's a perfect example of why Maps suck for domain models (not a criticism, just a point).  When exactly does a Map "have" a property?  There are two possibilities:
> 
> 1) A Map has properties based on whether it "containsKey" for the given property name.
>     - Caveat:  In some cases you'll find yourself having to set keys in the Map before they'll work with a given statement as a parameter or predefined result.  Perhaps this is better, simply because it is more explicit.
> 
> -OR-
> 
> 2) Because a Map is so loosely described, a Map can be said to have ANY property --all the time, no matter what keys are currently on it. 
>     - Caveat: <isPropertyAvailable>  will always return true.
> 
> So before I swing the pendulum back towards option #1, I wonder if you guys can possibly use <isNotNull> instead of <isPresent>?
> 
> PS:  It's not so much that we're busy, but in fact our source tree has been locked for two weeks in transition to ASF infrastructure....sad but true.
> 
> Cheers,
> Clinton
> 
> 
>>Nulls interpretted incorrectly in version 2.0.9
>>-----------------------------------------------
>>
>>         Key: IBATIS-51
>>         URL: http://issues.apache.org/jira/browse/IBATIS-51
>>     Project: iBatis for Java
>>        Type: Bug
>>  Components: SQL Maps
>>    Versions: 2.0.9
>> Environment: MySQL 3.23.x
>>    Reporter: Dimiter Kapitanov
> 
> 
>>When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
>>This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
>>Demonstration code :
>>-------------------------
>>[M.java]
>>import com.ibatis.sqlmap.client.SqlMapClient;
>>import com.ibatis.sqlmap.client.SqlMapClientBuilder;
>>import java.io.*;
>>import java.util.*;
>>/**
>> * Test for bug in iBatis DBL 2.0.9.
>> */
>>public class M
>>{
>>    public static void main(String[] args)
>>    {
>>        System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>>        System.out.println("If you run this program with iBatis 2.0.7 it " +
>>            "will return result, if you run it with iBatis 2.0.9 it will " +
>>            "return null.");
>>        
>>        try
>>        {
>>            String mapFile = "DB_Config.xml";
>>            Reader reader = new FileReader(mapFile);
>>            SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>>                reader);
>>            
>>            HashMap m = new HashMap();
>>            m.put("name", "Am");
>>            Map result = (Map)mapper.queryForObject("selectAccount", m);
>>            
>>            System.out.println("Result = " + result);
>>        }
>>        catch (Exception exc)
>>        {
>>            exc.printStackTrace(); 
>>        }
>>    }
>>} 
>>-------------------------
>>[DB_Config.xml]
>><?xml version="1.0" encoding="UTF-8" standalone="no"?>
>><!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
>><sqlMapConfig>
>>  <properties resource="debug.ini"/>
>>  <transactionManager type="JDBC">
>>    <dataSource type="SIMPLE">
>>      <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>>      <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>>      <property value="${DB_USER}" name="JDBC.Username"/>
>>      <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>>      <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
>>      <property value="15" name="Pool.MaximumActiveConnections"/>
>>      <property value="15" name="Pool.MaximumIdleConnections"/>
>>      <property value="1000" name="Pool.MaximumWait"/>
>>    </dataSource>
>>  </transactionManager>
>>  <sqlMap resource="Account.xml"/>
>>  
>></sqlMapConfig>
>>-------------------------
>>[Account.xml]
>><?xml version="1.0" encoding="UTF-8" standalone="no"?>
>><!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
>> "http://www.ibatis.com/dtd/sql-map-2.dtd">
>><sqlMap>
>>    <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>>        SELECT * FROM table1
>>        <dynamic prepend="WHERE">
>>        <isPropertyAvailable prepend="AND" property="id">
>>            id = #id#
>>        </isPropertyAvailable>
>>        <isPropertyAvailable prepend="AND" property="name">
>>            name = #name#
>>        </isPropertyAvailable>
>>        </dynamic>
>>        ORDER BY name
>>    </statement>
>></sqlMap>
>>---------------------
>>[debug.sql]
>>#
>># testDB SQL script (uses MySQL 3.23.x).
>>#
>>CREATE DATABASE testDB;
>>GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
>>FLUSH PRIVILEGES;
>>use testDB;
>>CREATE TABLE table1 (
>>  id int unsigned NOT NULL auto_increment primary key,
>>  name varchar(20)
>>);
>>insert into table1 values (1, 'Am');
>>insert into table1 values (2, 'Tam');
>>---------------------
>>[debug.ini]
>># 
>># testDB settings.
>>#
>>DB_DRIVER=com.mysql.jdbc.Driver
>>DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
>>DB_USER=testDB
>>DB_PASSWORD=testDB
>>DB_QUERY=select 1 from table1
> 
> 


[jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by "Clinton Begin (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58679 ]
     
Clinton Begin commented on IBATIS-51:
-------------------------------------

Thanks for figuring this one out Dimiter.

This was a concious decision made by us.  Previously a bug was entered that made sense...as you can see I've always been uncomfortable with the subject, as I even left the old code there. 

So, here's a perfect example of why Maps suck for domain models (not a criticism, just a point).  When exactly does a Map "have" a property?  There are two possibilities:

1) A Map has properties based on whether it "containsKey" for the given property name.
    - Caveat:  In some cases you'll find yourself having to set keys in the Map before they'll work with a given statement as a parameter or predefined result.  Perhaps this is better, simply because it is more explicit.

-OR-

2) Because a Map is so loosely described, a Map can be said to have ANY property --all the time, no matter what keys are currently on it. 
    - Caveat: <isPropertyAvailable>  will always return true.

So before I swing the pendulum back towards option #1, I wonder if you guys can possibly use <isNotNull> instead of <isPresent>?

PS:  It's not so much that we're busy, but in fact our source tree has been locked for two weeks in transition to ASF infrastructure....sad but true.

Cheers,
Clinton

> Nulls interpretted incorrectly in version 2.0.9
> -----------------------------------------------
>
>          Key: IBATIS-51
>          URL: http://issues.apache.org/jira/browse/IBATIS-51
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.9
>  Environment: MySQL 3.23.x
>     Reporter: Dimiter Kapitanov

>
> When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> Demonstration code :
> -------------------------
> [M.java]
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> import java.io.*;
> import java.util.*;
> /**
>  * Test for bug in iBatis DBL 2.0.9.
>  */
> public class M
> {
>     public static void main(String[] args)
>     {
>         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>         System.out.println("If you run this program with iBatis 2.0.7 it " +
>             "will return result, if you run it with iBatis 2.0.9 it will " +
>             "return null.");
>         
>         try
>         {
>             String mapFile = "DB_Config.xml";
>             Reader reader = new FileReader(mapFile);
>             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>                 reader);
>             
>             HashMap m = new HashMap();
>             m.put("name", "Am");
>             Map result = (Map)mapper.queryForObject("selectAccount", m);
>             
>             System.out.println("Result = " + result);
>         }
>         catch (Exception exc)
>         {
>             exc.printStackTrace(); 
>         }
>     }
> } 
> -------------------------
> [DB_Config.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> <sqlMapConfig>
>   <properties resource="debug.ini"/>
>   <transactionManager type="JDBC">
>     <dataSource type="SIMPLE">
>       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>       <property value="${DB_USER}" name="JDBC.Username"/>
>       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>       <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
>       <property value="15" name="Pool.MaximumActiveConnections"/>
>       <property value="15" name="Pool.MaximumIdleConnections"/>
>       <property value="1000" name="Pool.MaximumWait"/>
>     </dataSource>
>   </transactionManager>
>   <sqlMap resource="Account.xml"/>
>   
> </sqlMapConfig>
> -------------------------
> [Account.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
>  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> <sqlMap>
>     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>         SELECT * FROM table1
>         <dynamic prepend="WHERE">
>         <isPropertyAvailable prepend="AND" property="id">
>             id = #id#
>         </isPropertyAvailable>
>         <isPropertyAvailable prepend="AND" property="name">
>             name = #name#
>         </isPropertyAvailable>
>         </dynamic>
>         ORDER BY name
>     </statement>
> </sqlMap>
> ---------------------
> [debug.sql]
> #
> # testDB SQL script (uses MySQL 3.23.x).
> #
> CREATE DATABASE testDB;
> GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> FLUSH PRIVILEGES;
> use testDB;
> CREATE TABLE table1 (
>   id int unsigned NOT NULL auto_increment primary key,
>   name varchar(20)
> );
> insert into table1 values (1, 'Am');
> insert into table1 values (2, 'Tam');
> ---------------------
> [debug.ini]
> # 
> # testDB settings.
> #
> DB_DRIVER=com.mysql.jdbc.Driver
> DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> DB_USER=testDB
> DB_PASSWORD=testDB
> DB_QUERY=select 1 from table1

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Closed: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by "Clinton Begin (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-51?page=history ]
     
Clinton Begin closed IBATIS-51:
-------------------------------

      Assign To: Clinton Begin
     Resolution: Fixed
    Fix Version: 2.0.9b

Fixed as discussed.

> Nulls interpretted incorrectly in version 2.0.9
> -----------------------------------------------
>
>          Key: IBATIS-51
>          URL: http://issues.apache.org/jira/browse/IBATIS-51
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.9
>  Environment: MySQL 3.23.x
>     Reporter: Dimiter Kapitanov
>     Assignee: Clinton Begin
>      Fix For: 2.0.9b

>
> When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> Demonstration code :
> -------------------------
> [M.java]
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> import java.io.*;
> import java.util.*;
> /**
>  * Test for bug in iBatis DBL 2.0.9.
>  */
> public class M
> {
>     public static void main(String[] args)
>     {
>         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>         System.out.println("If you run this program with iBatis 2.0.7 it " +
>             "will return result, if you run it with iBatis 2.0.9 it will " +
>             "return null.");
>         
>         try
>         {
>             String mapFile = "DB_Config.xml";
>             Reader reader = new FileReader(mapFile);
>             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>                 reader);
>             
>             HashMap m = new HashMap();
>             m.put("name", "Am");
>             Map result = (Map)mapper.queryForObject("selectAccount", m);
>             
>             System.out.println("Result = " + result);
>         }
>         catch (Exception exc)
>         {
>             exc.printStackTrace(); 
>         }
>     }
> } 
> -------------------------
> [DB_Config.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> <sqlMapConfig>
>   <properties resource="debug.ini"/>
>   <transactionManager type="JDBC">
>     <dataSource type="SIMPLE">
>       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>       <property value="${DB_USER}" name="JDBC.Username"/>
>       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>       <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
>       <property value="15" name="Pool.MaximumActiveConnections"/>
>       <property value="15" name="Pool.MaximumIdleConnections"/>
>       <property value="1000" name="Pool.MaximumWait"/>
>     </dataSource>
>   </transactionManager>
>   <sqlMap resource="Account.xml"/>
>   
> </sqlMapConfig>
> -------------------------
> [Account.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
>  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> <sqlMap>
>     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>         SELECT * FROM table1
>         <dynamic prepend="WHERE">
>         <isPropertyAvailable prepend="AND" property="id">
>             id = #id#
>         </isPropertyAvailable>
>         <isPropertyAvailable prepend="AND" property="name">
>             name = #name#
>         </isPropertyAvailable>
>         </dynamic>
>         ORDER BY name
>     </statement>
> </sqlMap>
> ---------------------
> [debug.sql]
> #
> # testDB SQL script (uses MySQL 3.23.x).
> #
> CREATE DATABASE testDB;
> GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> FLUSH PRIVILEGES;
> use testDB;
> CREATE TABLE table1 (
>   id int unsigned NOT NULL auto_increment primary key,
>   name varchar(20)
> );
> insert into table1 values (1, 'Am');
> insert into table1 values (2, 'Tam');
> ---------------------
> [debug.ini]
> # 
> # testDB settings.
> #
> DB_DRIVER=com.mysql.jdbc.Driver
> DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> DB_USER=testDB
> DB_PASSWORD=testDB
> DB_QUERY=select 1 from table1

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by "Clinton Begin (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58768 ]
     
Clinton Begin commented on IBATIS-51:
-------------------------------------


Dimiter,

Thank you for the explanation.

I would like to fix this for you.  What would you think if we just fixed the isPropertyAvailable tag to explicitly handle maps and keys.  That way we can allow the Probe classes to maintain their current behaviour (which otherwise would cause others problems).  

So the isPropertyAvailable tag would know how to check for Map keys explicitly.  

I'm okay with this, as like I said before this tag is really only useful for  Maps now anyway.

This will solve cases 2 and 3. 

Your thoughts?  Give me a +1 and it will be in the next release.

> Nulls interpretted incorrectly in version 2.0.9
> -----------------------------------------------
>
>          Key: IBATIS-51
>          URL: http://issues.apache.org/jira/browse/IBATIS-51
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.9
>  Environment: MySQL 3.23.x
>     Reporter: Dimiter Kapitanov

>
> When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> Demonstration code :
> -------------------------
> [M.java]
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> import java.io.*;
> import java.util.*;
> /**
>  * Test for bug in iBatis DBL 2.0.9.
>  */
> public class M
> {
>     public static void main(String[] args)
>     {
>         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>         System.out.println("If you run this program with iBatis 2.0.7 it " +
>             "will return result, if you run it with iBatis 2.0.9 it will " +
>             "return null.");
>         
>         try
>         {
>             String mapFile = "DB_Config.xml";
>             Reader reader = new FileReader(mapFile);
>             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>                 reader);
>             
>             HashMap m = new HashMap();
>             m.put("name", "Am");
>             Map result = (Map)mapper.queryForObject("selectAccount", m);
>             
>             System.out.println("Result = " + result);
>         }
>         catch (Exception exc)
>         {
>             exc.printStackTrace(); 
>         }
>     }
> } 
> -------------------------
> [DB_Config.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> <sqlMapConfig>
>   <properties resource="debug.ini"/>
>   <transactionManager type="JDBC">
>     <dataSource type="SIMPLE">
>       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>       <property value="${DB_USER}" name="JDBC.Username"/>
>       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>       <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
>       <property value="15" name="Pool.MaximumActiveConnections"/>
>       <property value="15" name="Pool.MaximumIdleConnections"/>
>       <property value="1000" name="Pool.MaximumWait"/>
>     </dataSource>
>   </transactionManager>
>   <sqlMap resource="Account.xml"/>
>   
> </sqlMapConfig>
> -------------------------
> [Account.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
>  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> <sqlMap>
>     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>         SELECT * FROM table1
>         <dynamic prepend="WHERE">
>         <isPropertyAvailable prepend="AND" property="id">
>             id = #id#
>         </isPropertyAvailable>
>         <isPropertyAvailable prepend="AND" property="name">
>             name = #name#
>         </isPropertyAvailable>
>         </dynamic>
>         ORDER BY name
>     </statement>
> </sqlMap>
> ---------------------
> [debug.sql]
> #
> # testDB SQL script (uses MySQL 3.23.x).
> #
> CREATE DATABASE testDB;
> GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> FLUSH PRIVILEGES;
> use testDB;
> CREATE TABLE table1 (
>   id int unsigned NOT NULL auto_increment primary key,
>   name varchar(20)
> );
> insert into table1 values (1, 'Am');
> insert into table1 values (2, 'Tam');
> ---------------------
> [debug.ini]
> # 
> # testDB settings.
> #
> DB_DRIVER=com.mysql.jdbc.Driver
> DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> DB_USER=testDB
> DB_PASSWORD=testDB
> DB_QUERY=select 1 from table1

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by "Philippe Laflamme (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_57889 ]
     
Philippe Laflamme commented on IBATIS-51:
-----------------------------------------

I posted this question on the java-user list about a month ago:

http://www.mail-archive.com/ibatis-user-java@incubator.apache.org/msg00171.html

It was not very clear to me if this was considered as a bug or not. Can someone from the dev team clarify this issue?

I'd like to upgrade the iBatis version soon and this issue affects how/if I'll need handle the isPropertyAvailable tags we're using.

Thanks

> Nulls interpretted incorrectly in version 2.0.9
> -----------------------------------------------
>
>          Key: IBATIS-51
>          URL: http://issues.apache.org/jira/browse/IBATIS-51
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.9
>  Environment: MySQL 3.23.x
>     Reporter: Dimiter Kapitanov

>
> When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> Demonstration code :
> -------------------------
> [M.java]
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> import java.io.*;
> import java.util.*;
> /**
>  * Test for bug in iBatis DBL 2.0.9.
>  */
> public class M
> {
>     public static void main(String[] args)
>     {
>         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>         System.out.println("If you run this program with iBatis 2.0.7 it " +
>             "will return result, if you run it with iBatis 2.0.9 it will " +
>             "return null.");
>         
>         try
>         {
>             String mapFile = "DB_Config.xml";
>             Reader reader = new FileReader(mapFile);
>             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>                 reader);
>             
>             HashMap m = new HashMap();
>             m.put("name", "Am");
>             Map result = (Map)mapper.queryForObject("selectAccount", m);
>             
>             System.out.println("Result = " + result);
>         }
>         catch (Exception exc)
>         {
>             exc.printStackTrace(); 
>         }
>     }
> } 
> -------------------------
> [DB_Config.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> <sqlMapConfig>
>   <properties resource="debug.ini"/>
>   <transactionManager type="JDBC">
>     <dataSource type="SIMPLE">
>       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>       <property value="${DB_USER}" name="JDBC.Username"/>
>       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>       <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
>       <property value="15" name="Pool.MaximumActiveConnections"/>
>       <property value="15" name="Pool.MaximumIdleConnections"/>
>       <property value="1000" name="Pool.MaximumWait"/>
>     </dataSource>
>   </transactionManager>
>   <sqlMap resource="Account.xml"/>
>   
> </sqlMapConfig>
> -------------------------
> [Account.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
>  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> <sqlMap>
>     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>         SELECT * FROM table1
>         <dynamic prepend="WHERE">
>         <isPropertyAvailable prepend="AND" property="id">
>             id = #id#
>         </isPropertyAvailable>
>         <isPropertyAvailable prepend="AND" property="name">
>             name = #name#
>         </isPropertyAvailable>
>         </dynamic>
>         ORDER BY name
>     </statement>
> </sqlMap>
> ---------------------
> [debug.sql]
> #
> # testDB SQL script (uses MySQL 3.23.x).
> #
> CREATE DATABASE testDB;
> GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> FLUSH PRIVILEGES;
> use testDB;
> CREATE TABLE table1 (
>   id int unsigned NOT NULL auto_increment primary key,
>   name varchar(20)
> );
> insert into table1 values (1, 'Am');
> insert into table1 values (2, 'Tam');
> ---------------------
> [debug.ini]
> # 
> # testDB settings.
> #
> DB_DRIVER=com.mysql.jdbc.Driver
> DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> DB_USER=testDB
> DB_PASSWORD=testDB
> DB_QUERY=select 1 from table1

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by "Dimiter Kapitanov (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58675 ]
     
Dimiter Kapitanov commented on IBATIS-51:
-----------------------------------------

It seems iBatis developers are quite busy. So I checked the sources.
The reason is in class :
com.ibatis.common.beans.ComplexBeanProbe.java (rows 248 and 275)
In iBatis DBL 2.0.7 they were :
hasProperty = ((Map) object).containsKey(propertyName);
now in iBatis 2.0.9 it is :
hasProperty = true;//((Map) object).containsKey(propertyName);
So - if you use Map as parameter object, iBatis thinks any property exist.
This broke 'the contract' and back compatibility (any regression tests ?).
My suggestion is : please restore previous behaviour. Our applications rely on it. 
Thank you for your attention.

> Nulls interpretted incorrectly in version 2.0.9
> -----------------------------------------------
>
>          Key: IBATIS-51
>          URL: http://issues.apache.org/jira/browse/IBATIS-51
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.9
>  Environment: MySQL 3.23.x
>     Reporter: Dimiter Kapitanov

>
> When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> Demonstration code :
> -------------------------
> [M.java]
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> import java.io.*;
> import java.util.*;
> /**
>  * Test for bug in iBatis DBL 2.0.9.
>  */
> public class M
> {
>     public static void main(String[] args)
>     {
>         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>         System.out.println("If you run this program with iBatis 2.0.7 it " +
>             "will return result, if you run it with iBatis 2.0.9 it will " +
>             "return null.");
>         
>         try
>         {
>             String mapFile = "DB_Config.xml";
>             Reader reader = new FileReader(mapFile);
>             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>                 reader);
>             
>             HashMap m = new HashMap();
>             m.put("name", "Am");
>             Map result = (Map)mapper.queryForObject("selectAccount", m);
>             
>             System.out.println("Result = " + result);
>         }
>         catch (Exception exc)
>         {
>             exc.printStackTrace(); 
>         }
>     }
> } 
> -------------------------
> [DB_Config.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> <sqlMapConfig>
>   <properties resource="debug.ini"/>
>   <transactionManager type="JDBC">
>     <dataSource type="SIMPLE">
>       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>       <property value="${DB_USER}" name="JDBC.Username"/>
>       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>       <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
>       <property value="15" name="Pool.MaximumActiveConnections"/>
>       <property value="15" name="Pool.MaximumIdleConnections"/>
>       <property value="1000" name="Pool.MaximumWait"/>
>     </dataSource>
>   </transactionManager>
>   <sqlMap resource="Account.xml"/>
>   
> </sqlMapConfig>
> -------------------------
> [Account.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
>  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> <sqlMap>
>     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>         SELECT * FROM table1
>         <dynamic prepend="WHERE">
>         <isPropertyAvailable prepend="AND" property="id">
>             id = #id#
>         </isPropertyAvailable>
>         <isPropertyAvailable prepend="AND" property="name">
>             name = #name#
>         </isPropertyAvailable>
>         </dynamic>
>         ORDER BY name
>     </statement>
> </sqlMap>
> ---------------------
> [debug.sql]
> #
> # testDB SQL script (uses MySQL 3.23.x).
> #
> CREATE DATABASE testDB;
> GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> FLUSH PRIVILEGES;
> use testDB;
> CREATE TABLE table1 (
>   id int unsigned NOT NULL auto_increment primary key,
>   name varchar(20)
> );
> insert into table1 values (1, 'Am');
> insert into table1 values (2, 'Tam');
> ---------------------
> [debug.ini]
> # 
> # testDB settings.
> #
> DB_DRIVER=com.mysql.jdbc.Driver
> DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> DB_USER=testDB
> DB_PASSWORD=testDB
> DB_QUERY=select 1 from table1

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by "Dimiter Kapitanov (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58805 ]
     
Dimiter Kapitanov commented on IBATIS-51:
-----------------------------------------

Thank you very much for your understanding, Clinton. You said the things clearly, and I have nothing different to supplement. So I am looking for the next version. :-)
Have a nice day !

> Nulls interpretted incorrectly in version 2.0.9
> -----------------------------------------------
>
>          Key: IBATIS-51
>          URL: http://issues.apache.org/jira/browse/IBATIS-51
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.9
>  Environment: MySQL 3.23.x
>     Reporter: Dimiter Kapitanov

>
> When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> Demonstration code :
> -------------------------
> [M.java]
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> import java.io.*;
> import java.util.*;
> /**
>  * Test for bug in iBatis DBL 2.0.9.
>  */
> public class M
> {
>     public static void main(String[] args)
>     {
>         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>         System.out.println("If you run this program with iBatis 2.0.7 it " +
>             "will return result, if you run it with iBatis 2.0.9 it will " +
>             "return null.");
>         
>         try
>         {
>             String mapFile = "DB_Config.xml";
>             Reader reader = new FileReader(mapFile);
>             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>                 reader);
>             
>             HashMap m = new HashMap();
>             m.put("name", "Am");
>             Map result = (Map)mapper.queryForObject("selectAccount", m);
>             
>             System.out.println("Result = " + result);
>         }
>         catch (Exception exc)
>         {
>             exc.printStackTrace(); 
>         }
>     }
> } 
> -------------------------
> [DB_Config.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> <sqlMapConfig>
>   <properties resource="debug.ini"/>
>   <transactionManager type="JDBC">
>     <dataSource type="SIMPLE">
>       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>       <property value="${DB_USER}" name="JDBC.Username"/>
>       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>       <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
>       <property value="15" name="Pool.MaximumActiveConnections"/>
>       <property value="15" name="Pool.MaximumIdleConnections"/>
>       <property value="1000" name="Pool.MaximumWait"/>
>     </dataSource>
>   </transactionManager>
>   <sqlMap resource="Account.xml"/>
>   
> </sqlMapConfig>
> -------------------------
> [Account.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
>  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> <sqlMap>
>     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>         SELECT * FROM table1
>         <dynamic prepend="WHERE">
>         <isPropertyAvailable prepend="AND" property="id">
>             id = #id#
>         </isPropertyAvailable>
>         <isPropertyAvailable prepend="AND" property="name">
>             name = #name#
>         </isPropertyAvailable>
>         </dynamic>
>         ORDER BY name
>     </statement>
> </sqlMap>
> ---------------------
> [debug.sql]
> #
> # testDB SQL script (uses MySQL 3.23.x).
> #
> CREATE DATABASE testDB;
> GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> FLUSH PRIVILEGES;
> use testDB;
> CREATE TABLE table1 (
>   id int unsigned NOT NULL auto_increment primary key,
>   name varchar(20)
> );
> insert into table1 values (1, 'Am');
> insert into table1 values (2, 'Tam');
> ---------------------
> [debug.ini]
> # 
> # testDB settings.
> #
> DB_DRIVER=com.mysql.jdbc.Driver
> DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> DB_USER=testDB
> DB_PASSWORD=testDB
> DB_QUERY=select 1 from table1

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Commented: (IBATIS-51) Nulls interpretted incorrectly in version 2.0.9

Posted by "Dimiter Kapitanov (JIRA)" <ib...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/IBATIS-51?page=comments#action_58749 ]
     
Dimiter Kapitanov commented on IBATIS-51:
-----------------------------------------

Hello Clinton.
Thank you for your reply. I understand what you meen, but let me explain the other point of view. 
We have a project with HUGE domain model. We use Map as replacement of all java-beans (yes I am serious). iBatis is perfect for this, because it doesn't force us to use 'classic-only' things. 
Imagine this 3 possible cases :

1) parameterClass : Map[key1=value1]
iBatis : insert/update field 'key1' to new value.

2) parameterClass : Map[key1=null]
iBatis : clear the value of 'key1'.

3) parameterClass : Map[key2=value2] (no property 'key1')
iBatis : keep 'key1' as is, but update 'key2'.

If <isPropertyAvailable> works differently for Maps and JavaBeans properties, we cannot distinguish case 2) and 3). Even <isNotNull> cannot help us in this case.
Please, consider again 'isPropertyAvailable' behaviour - for all these who use Maps.

All the best, 
Dimiter

> Nulls interpretted incorrectly in version 2.0.9
> -----------------------------------------------
>
>          Key: IBATIS-51
>          URL: http://issues.apache.org/jira/browse/IBATIS-51
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.9
>  Environment: MySQL 3.23.x
>     Reporter: Dimiter Kapitanov

>
> When use HashMap as parameter class, SQL query is consturcted (with nulls) even for missing properties.
> This is new bug, appeared in iBatis DBL 2.0.9 (it didn't exist in iBatis DBL 2.0.7).
> Demonstration code :
> -------------------------
> [M.java]
> import com.ibatis.sqlmap.client.SqlMapClient;
> import com.ibatis.sqlmap.client.SqlMapClientBuilder;
> import java.io.*;
> import java.util.*;
> /**
>  * Test for bug in iBatis DBL 2.0.9.
>  */
> public class M
> {
>     public static void main(String[] args)
>     {
>         System.out.println("Testing iBatis DBL 2.0.9 bug : ");
>         System.out.println("If you run this program with iBatis 2.0.7 it " +
>             "will return result, if you run it with iBatis 2.0.9 it will " +
>             "return null.");
>         
>         try
>         {
>             String mapFile = "DB_Config.xml";
>             Reader reader = new FileReader(mapFile);
>             SqlMapClient mapper = SqlMapClientBuilder.buildSqlMapClient(
>                 reader);
>             
>             HashMap m = new HashMap();
>             m.put("name", "Am");
>             Map result = (Map)mapper.queryForObject("selectAccount", m);
>             
>             System.out.println("Result = " + result);
>         }
>         catch (Exception exc)
>         {
>             exc.printStackTrace(); 
>         }
>     }
> } 
> -------------------------
> [DB_Config.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN" "http://www.ibatis.com/dtd/sql-map-config-2.dtd">
> <sqlMapConfig>
>   <properties resource="debug.ini"/>
>   <transactionManager type="JDBC">
>     <dataSource type="SIMPLE">
>       <property value="${DB_DRIVER}" name="JDBC.Driver"/>
>       <property value="${DB_URL}" name="JDBC.ConnectionURL"/>
>       <property value="${DB_USER}" name="JDBC.Username"/>
>       <property value="${DB_PASSWORD}" name="JDBC.Password"/>
>       <property value="${DB_QUERY}" name="Pool.PingQuery"/>        
>       <property value="15" name="Pool.MaximumActiveConnections"/>
>       <property value="15" name="Pool.MaximumIdleConnections"/>
>       <property value="1000" name="Pool.MaximumWait"/>
>     </dataSource>
>   </transactionManager>
>   <sqlMap resource="Account.xml"/>
>   
> </sqlMapConfig>
> -------------------------
> [Account.xml]
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" 
>  "http://www.ibatis.com/dtd/sql-map-2.dtd">
> <sqlMap>
>     <statement id="selectAccount" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
>         SELECT * FROM table1
>         <dynamic prepend="WHERE">
>         <isPropertyAvailable prepend="AND" property="id">
>             id = #id#
>         </isPropertyAvailable>
>         <isPropertyAvailable prepend="AND" property="name">
>             name = #name#
>         </isPropertyAvailable>
>         </dynamic>
>         ORDER BY name
>     </statement>
> </sqlMap>
> ---------------------
> [debug.sql]
> #
> # testDB SQL script (uses MySQL 3.23.x).
> #
> CREATE DATABASE testDB;
> GRANT ALL PRIVILEGES ON testDB.* TO 'testDB'@'localhost' IDENTIFIED BY 'testDB';
> FLUSH PRIVILEGES;
> use testDB;
> CREATE TABLE table1 (
>   id int unsigned NOT NULL auto_increment primary key,
>   name varchar(20)
> );
> insert into table1 values (1, 'Am');
> insert into table1 values (2, 'Tam');
> ---------------------
> [debug.ini]
> # 
> # testDB settings.
> #
> DB_DRIVER=com.mysql.jdbc.Driver
> DB_URL=jdbc:mysql://localhost/testDB?useUnicode=true
> DB_USER=testDB
> DB_PASSWORD=testDB
> DB_QUERY=select 1 from table1

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira