You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Iwao AVE! (JIRA)" <ib...@incubator.apache.org> on 2005/11/01 09:32:55 UTC
[jira] Created: (IBATIS-213) SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
------------------------------------------------------------------------------------------------------
Key: IBATIS-213
URL: http://issues.apache.org/jira/browse/IBATIS-213
Project: iBatis for Java
Type: Bug
Components: SQL Maps
Versions: 2.1.5
Environment: PowerMac G5 1.8GHz dual, 2.25GB RAM, Mac OS X 10.4.2
Using SqlMaps from tomcat via spring framework.
Reporter: Iwao AVE!
[Preparation]
-- Database
CREATE TABLE parent ( parentId, parentName );
CREATE TABLE child ( childId, parentId, childName, childAge );
INSERT INTO parent ( parentId, parentName ) VALUES ( 1, 'Mr Parent' );
-- Java classes.
public class Parent
{
private int parentId;
private String parentName;
private List childList;
// accessor methods...
}
public class Child
{
private int childId;
private String childName;
private int childAge;
// accessor methods...
}
--SqlMap.
<sqlMap namespace="Family">
<resultMap id="parentResult" class="Parent" groupBy="parentId">
<result property="parentId" column="parentId"/>
<result property="parentName" column="parentName"/>
<result property="childList" resultMap="Family.childResult"/>
</resultMap>
<resultMap id="childResult" class="Child">
<result property="childId" column="childId"/>
<result property="childName" column="childName"/>
<result property="childAge" column="childAge" nullValue="0"/>
</resultMap>
<select id="getParent" resultMap="parentResult" parameterClass="int">
SELECT
parent.parentId, parent.parentName,
child.childId, child.childName, child.childAge
FROM parent
LEFT JOIN child ON parent.parentId = child.parentId
WHERE
parent.parentId = #value#
</select>
</sqlMap>
--
[Test]
Executing statement "getParent" with parameter '1'.
[Expected result]
Query returns 1 'Parent' object and 'childList' property of it is empty (doesn't mean null).
[Actual result]
The 'childList' property of the returned 'Parent' contains 1 'Child' object.
[Additional information]
If 'nullValue' is not specified in 'childResult', it works as expected.
But this, of course, causes an error if there is a row in the 'child' table and the 'childAge' column is null.
--
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
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Commented: (IBATIS-213) SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
Posted by "Sven Boden (JIRA)" <ib...@incubator.apache.org>.
[ http://issues.apache.org/jira/browse/IBATIS-213?page=comments#action_12358567 ]
Sven Boden commented on IBATIS-213:
-----------------------------------
Attached file fixes IBATIS-213. I had to split getPrimitiveResultMappingValue() in 2 methods to be able to make the distinction between a null and its replacement value.
All existing JUnit test cases still work.
Sven
> SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
> ------------------------------------------------------------------------------------------------------
>
> Key: IBATIS-213
> URL: http://issues.apache.org/jira/browse/IBATIS-213
> Project: iBatis for Java
> Type: Bug
> Components: SQL Maps
> Versions: 2.1.5
> Environment: PowerMac G5 1.8GHz dual, 2.25GB RAM, Mac OS X 10.4.2
> Using SqlMaps from tomcat via spring framework.
> Reporter: Iwao AVE!
> Attachments: BasicResultMap.java
>
> [Preparation]
> -- Database
> CREATE TABLE parent ( parentId, parentName );
> CREATE TABLE child ( childId, parentId, childName, childAge );
> INSERT INTO parent ( parentId, parentName ) VALUES ( 1, 'Mr Parent' );
> -- Java classes.
> public class Parent
> {
> private int parentId;
> private String parentName;
> private List childList;
> // accessor methods...
> }
> public class Child
> {
> private int childId;
> private String childName;
> private int childAge;
> // accessor methods...
> }
> --SqlMap.
> <sqlMap namespace="Family">
> <resultMap id="parentResult" class="Parent" groupBy="parentId">
> <result property="parentId" column="parentId"/>
> <result property="parentName" column="parentName"/>
> <result property="childList" resultMap="Family.childResult"/>
> </resultMap>
> <resultMap id="childResult" class="Child">
> <result property="childId" column="childId"/>
> <result property="childName" column="childName"/>
> <result property="childAge" column="childAge" nullValue="0"/>
> </resultMap>
> <select id="getParent" resultMap="parentResult" parameterClass="int">
> SELECT
> parent.parentId, parent.parentName,
> child.childId, child.childName, child.childAge
> FROM parent
> LEFT JOIN child ON parent.parentId = child.parentId
> WHERE
> parent.parentId = #value#
> </select>
> </sqlMap>
> --
> [Test]
> Executing statement "getParent" with parameter '1'.
> [Expected result]
> Query returns 1 'Parent' object and 'childList' property of it is empty (doesn't mean null).
> [Actual result]
> The 'childList' property of the returned 'Parent' contains 1 'Child' object.
> [Additional information]
> If 'nullValue' is not specified in 'childResult', it works as expected.
> But this, of course, causes an error if there is a row in the 'child' table and the 'childAge' column is null.
--
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
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Commented: (IBATIS-213) SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
Posted by "Sven Boden (JIRA)" <ib...@incubator.apache.org>.
[ http://issues.apache.org/jira/browse/IBATIS-213?page=comments#action_12358564 ]
Sven Boden commented on IBATIS-213:
-----------------------------------
I've debugged the "problem" and made a testcase for it.
The problem is in com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getResults() and getPrimitiveResultMappingValue(). When all retrieved properties for a nested object are "java null" the nested object is not created.
Of course with the nullvalue attribute this is just what is never true. I'll see what I can do to fix it.
> SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
> ------------------------------------------------------------------------------------------------------
>
> Key: IBATIS-213
> URL: http://issues.apache.org/jira/browse/IBATIS-213
> Project: iBatis for Java
> Type: Bug
> Components: SQL Maps
> Versions: 2.1.5
> Environment: PowerMac G5 1.8GHz dual, 2.25GB RAM, Mac OS X 10.4.2
> Using SqlMaps from tomcat via spring framework.
> Reporter: Iwao AVE!
>
> [Preparation]
> -- Database
> CREATE TABLE parent ( parentId, parentName );
> CREATE TABLE child ( childId, parentId, childName, childAge );
> INSERT INTO parent ( parentId, parentName ) VALUES ( 1, 'Mr Parent' );
> -- Java classes.
> public class Parent
> {
> private int parentId;
> private String parentName;
> private List childList;
> // accessor methods...
> }
> public class Child
> {
> private int childId;
> private String childName;
> private int childAge;
> // accessor methods...
> }
> --SqlMap.
> <sqlMap namespace="Family">
> <resultMap id="parentResult" class="Parent" groupBy="parentId">
> <result property="parentId" column="parentId"/>
> <result property="parentName" column="parentName"/>
> <result property="childList" resultMap="Family.childResult"/>
> </resultMap>
> <resultMap id="childResult" class="Child">
> <result property="childId" column="childId"/>
> <result property="childName" column="childName"/>
> <result property="childAge" column="childAge" nullValue="0"/>
> </resultMap>
> <select id="getParent" resultMap="parentResult" parameterClass="int">
> SELECT
> parent.parentId, parent.parentName,
> child.childId, child.childName, child.childAge
> FROM parent
> LEFT JOIN child ON parent.parentId = child.parentId
> WHERE
> parent.parentId = #value#
> </select>
> </sqlMap>
> --
> [Test]
> Executing statement "getParent" with parameter '1'.
> [Expected result]
> Query returns 1 'Parent' object and 'childList' property of it is empty (doesn't mean null).
> [Actual result]
> The 'childList' property of the returned 'Parent' contains 1 'Child' object.
> [Additional information]
> If 'nullValue' is not specified in 'childResult', it works as expected.
> But this, of course, causes an error if there is a row in the 'child' table and the 'childAge' column is null.
--
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
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Updated: (IBATIS-213) SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
Posted by "Anonymous (JIRA)" <ib...@incubator.apache.org>.
[ http://issues.apache.org/jira/browse/IBATIS-213?page=all ]
updated IBATIS-213:
--------------------
Attachment: BasicResultMap.java
> SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
> ------------------------------------------------------------------------------------------------------
>
> Key: IBATIS-213
> URL: http://issues.apache.org/jira/browse/IBATIS-213
> Project: iBatis for Java
> Type: Bug
> Components: SQL Maps
> Versions: 2.1.5
> Environment: PowerMac G5 1.8GHz dual, 2.25GB RAM, Mac OS X 10.4.2
> Using SqlMaps from tomcat via spring framework.
> Reporter: Iwao AVE!
> Attachments: BasicResultMap.java
>
> [Preparation]
> -- Database
> CREATE TABLE parent ( parentId, parentName );
> CREATE TABLE child ( childId, parentId, childName, childAge );
> INSERT INTO parent ( parentId, parentName ) VALUES ( 1, 'Mr Parent' );
> -- Java classes.
> public class Parent
> {
> private int parentId;
> private String parentName;
> private List childList;
> // accessor methods...
> }
> public class Child
> {
> private int childId;
> private String childName;
> private int childAge;
> // accessor methods...
> }
> --SqlMap.
> <sqlMap namespace="Family">
> <resultMap id="parentResult" class="Parent" groupBy="parentId">
> <result property="parentId" column="parentId"/>
> <result property="parentName" column="parentName"/>
> <result property="childList" resultMap="Family.childResult"/>
> </resultMap>
> <resultMap id="childResult" class="Child">
> <result property="childId" column="childId"/>
> <result property="childName" column="childName"/>
> <result property="childAge" column="childAge" nullValue="0"/>
> </resultMap>
> <select id="getParent" resultMap="parentResult" parameterClass="int">
> SELECT
> parent.parentId, parent.parentName,
> child.childId, child.childName, child.childAge
> FROM parent
> LEFT JOIN child ON parent.parentId = child.parentId
> WHERE
> parent.parentId = #value#
> </select>
> </sqlMap>
> --
> [Test]
> Executing statement "getParent" with parameter '1'.
> [Expected result]
> Query returns 1 'Parent' object and 'childList' property of it is empty (doesn't mean null).
> [Actual result]
> The 'childList' property of the returned 'Parent' contains 1 'Child' object.
> [Additional information]
> If 'nullValue' is not specified in 'childResult', it works as expected.
> But this, of course, causes an error if there is a row in the 'child' table and the 'childAge' column is null.
--
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
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
[jira] Closed: (IBATIS-213) SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
Posted by "Clinton Begin (JIRA)" <ib...@incubator.apache.org>.
[ http://issues.apache.org/jira/browse/IBATIS-213?page=all ]
Clinton Begin closed IBATIS-213:
--------------------------------
Fix Version: 2.2.0
Resolution: Fixed
Assign To: Clinton Begin
Fixed as per Sven's patch. Thanks!
> SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.
> ------------------------------------------------------------------------------------------------------
>
> Key: IBATIS-213
> URL: http://issues.apache.org/jira/browse/IBATIS-213
> Project: iBatis for Java
> Type: Bug
> Components: SQL Maps
> Versions: 2.1.5
> Environment: PowerMac G5 1.8GHz dual, 2.25GB RAM, Mac OS X 10.4.2
> Using SqlMaps from tomcat via spring framework.
> Reporter: Iwao AVE!
> Assignee: Clinton Begin
> Fix For: 2.2.0
> Attachments: BasicResultMap.java
>
> [Preparation]
> -- Database
> CREATE TABLE parent ( parentId, parentName );
> CREATE TABLE child ( childId, parentId, childName, childAge );
> INSERT INTO parent ( parentId, parentName ) VALUES ( 1, 'Mr Parent' );
> -- Java classes.
> public class Parent
> {
> private int parentId;
> private String parentName;
> private List childList;
> // accessor methods...
> }
> public class Child
> {
> private int childId;
> private String childName;
> private int childAge;
> // accessor methods...
> }
> --SqlMap.
> <sqlMap namespace="Family">
> <resultMap id="parentResult" class="Parent" groupBy="parentId">
> <result property="parentId" column="parentId"/>
> <result property="parentName" column="parentName"/>
> <result property="childList" resultMap="Family.childResult"/>
> </resultMap>
> <resultMap id="childResult" class="Child">
> <result property="childId" column="childId"/>
> <result property="childName" column="childName"/>
> <result property="childAge" column="childAge" nullValue="0"/>
> </resultMap>
> <select id="getParent" resultMap="parentResult" parameterClass="int">
> SELECT
> parent.parentId, parent.parentName,
> child.childId, child.childName, child.childAge
> FROM parent
> LEFT JOIN child ON parent.parentId = child.parentId
> WHERE
> parent.parentId = #value#
> </select>
> </sqlMap>
> --
> [Test]
> Executing statement "getParent" with parameter '1'.
> [Expected result]
> Query returns 1 'Parent' object and 'childList' property of it is empty (doesn't mean null).
> [Actual result]
> The 'childList' property of the returned 'Parent' contains 1 'Child' object.
> [Additional information]
> If 'nullValue' is not specified in 'childResult', it works as expected.
> But this, of course, causes an error if there is a row in the 'child' table and the 'childAge' column is null.
--
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
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira