You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ibatis.apache.org by "Stefan Langer (JIRA)" <ib...@incubator.apache.org> on 2006/12/01 09:46:20 UTC

[jira] Created: (IBATIS-375) Provide a way for not creating items from nested ResultMaps when the items contain only null values

Provide a way for not creating items from nested ResultMaps when the items contain only null values
---------------------------------------------------------------------------------------------------

                 Key: IBATIS-375
                 URL: http://issues.apache.org/jira/browse/IBATIS-375
             Project: iBatis for Java
          Issue Type: Improvement
          Components: SQL Maps
    Affects Versions: 2.2.0
            Reporter: Stefan Langer


Taken the following resultmaps (uneeded parts are left out) for a simple domainmodel where notebook contains 0 or more pages.

<resultMap class="notebook" groupBy="id" id="notebookResult">
   <result column="NB_ID" jdbcType="VARCHAR" property="id"/>
   <result javaType="java.util.List" property="pages" resultMap="Note.pageResult"/>
</resultMap>

<resultMap class="page" groupBy="id" id="pageResult">
  <result column="P_ID" jdbcType="VARCHAR" property="id"/>
</resultMap> 

and the following select statement:
<select id="selectNotebook" parameterClass="java.lang.String" resultMap="notebookResult">
SELECT nb.id as nb_id, p.id as p_id,    
FROM notebook nb LEFT JOIN page p ON nb.id = p.notebook_id
WHERE nb.id = #id#
</select> 

Do to the left join this query will always result in at least one page being created even though the pages are actually empty. 
It would be nice if the mapping framework could somehow not create these empty objects. 
The following suggestions come to mind: 
Either do not create objects where all parameters are null (this indicates the left or right join scenario)
or provide a way to tag a property in the resultMap which may not be null in order for the object to be created.
Example:
<resultMap class="page" groupBy="id" id="pageResult">
  <result column="P_ID" jdbcType="VARCHAR" property="id" doNotCreateOnNull="true"/>
</resultMap> 
This would greatly ease the use of complex mappings where one wants to prevent the dreaded N+1 Select Problem.

-- 
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] Issue Comment Edited: (IBATIS-375) Provide a way for not creating items from nested ResultMaps when the items contain only null values

Posted by "Ian Zabel (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12614534#action_12614534 ] 

ianzabel edited comment on IBATIS-375 at 7/17/08 6:24 PM:
-----------------------------------------------------------

I've taken the work done by Sylvain Laurent and updated it to work with iBatis 2.3.3 (HEAD as of this writing). It's a pretty minor change overall.

Attaching a PATCH, as this should make it much easier to apply to SVN.

      was (Author: ianzabel):
    I've taken the work done by Stefan and updated it to work with iBatis 2.3.3 (HEAD as of this writing). It's a pretty minor change overall.

Attaching a PATCH, as this should make it much easier to apply to SVN.
  
> Provide a way for not creating items from nested ResultMaps when the items contain only null values
> ---------------------------------------------------------------------------------------------------
>
>                 Key: IBATIS-375
>                 URL: https://issues.apache.org/jira/browse/IBATIS-375
>             Project: iBatis for Java
>          Issue Type: Improvement
>          Components: SQL Maps
>    Affects Versions: 2.2.0
>            Reporter: Stefan Langer
>         Attachments: BasicResultMap.java, BasicResultMapping.java, iBATIS-375.patch, sql-map-2.dtd, SqlMapParser.java
>
>
> Taken the following resultmaps (uneeded parts are left out) for a simple domainmodel where notebook contains 0 or more pages.
> <resultMap class="notebook" groupBy="id" id="notebookResult">
>    <result column="NB_ID" jdbcType="VARCHAR" property="id"/>
>    <result javaType="java.util.List" property="pages" resultMap="Note.pageResult"/>
> </resultMap>
> <resultMap class="page" groupBy="id" id="pageResult">
>   <result column="P_ID" jdbcType="VARCHAR" property="id"/>
> </resultMap> 
> and the following select statement:
> <select id="selectNotebook" parameterClass="java.lang.String" resultMap="notebookResult">
> SELECT nb.id as nb_id, p.id as p_id,    
> FROM notebook nb LEFT JOIN page p ON nb.id = p.notebook_id
> WHERE nb.id = #id#
> </select> 
> Do to the left join this query will always result in at least one page being created even though the pages are actually empty. 
> It would be nice if the mapping framework could somehow not create these empty objects. 
> The following suggestions come to mind: 
> Either do not create objects where all parameters are null (this indicates the left or right join scenario)
> or provide a way to tag a property in the resultMap which may not be null in order for the object to be created.
> Example:
> <resultMap class="page" groupBy="id" id="pageResult">
>   <result column="P_ID" jdbcType="VARCHAR" property="id" doNotCreateOnNull="true"/>
> </resultMap> 
> This would greatly ease the use of complex mappings where one wants to prevent the dreaded N+1 Select Problem.

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


[jira] Closed: (IBATIS-375) Provide a way for not creating items from nested ResultMaps when the items contain only null values

Posted by "Clinton Begin (JIRA)" <ib...@incubator.apache.org>.
     [ https://issues.apache.org/jira/browse/IBATIS-375?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Clinton Begin closed IBATIS-375.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 2.3.4

applied patch

> Provide a way for not creating items from nested ResultMaps when the items contain only null values
> ---------------------------------------------------------------------------------------------------
>
>                 Key: IBATIS-375
>                 URL: https://issues.apache.org/jira/browse/IBATIS-375
>             Project: iBatis for Java
>          Issue Type: Improvement
>          Components: SQL Maps
>    Affects Versions: 2.2.0
>            Reporter: Stefan Langer
>             Fix For: 2.3.4
>
>         Attachments: BasicResultMap.java, BasicResultMapping.java, iBATIS-375.patch, sql-map-2.dtd, SqlMapParser.java
>
>
> Taken the following resultmaps (uneeded parts are left out) for a simple domainmodel where notebook contains 0 or more pages.
> <resultMap class="notebook" groupBy="id" id="notebookResult">
>    <result column="NB_ID" jdbcType="VARCHAR" property="id"/>
>    <result javaType="java.util.List" property="pages" resultMap="Note.pageResult"/>
> </resultMap>
> <resultMap class="page" groupBy="id" id="pageResult">
>   <result column="P_ID" jdbcType="VARCHAR" property="id"/>
> </resultMap> 
> and the following select statement:
> <select id="selectNotebook" parameterClass="java.lang.String" resultMap="notebookResult">
> SELECT nb.id as nb_id, p.id as p_id,    
> FROM notebook nb LEFT JOIN page p ON nb.id = p.notebook_id
> WHERE nb.id = #id#
> </select> 
> Do to the left join this query will always result in at least one page being created even though the pages are actually empty. 
> It would be nice if the mapping framework could somehow not create these empty objects. 
> The following suggestions come to mind: 
> Either do not create objects where all parameters are null (this indicates the left or right join scenario)
> or provide a way to tag a property in the resultMap which may not be null in order for the object to be created.
> Example:
> <resultMap class="page" groupBy="id" id="pageResult">
>   <result column="P_ID" jdbcType="VARCHAR" property="id" doNotCreateOnNull="true"/>
> </resultMap> 
> This would greatly ease the use of complex mappings where one wants to prevent the dreaded N+1 Select Problem.

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


[jira] Commented: (IBATIS-375) Provide a way for not creating items from nested ResultMaps when the items contain only null values

Posted by "Ian Zabel (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12614436#action_12614436 ] 

Ian Zabel commented on IBATIS-375:
----------------------------------

I'm surprised this improvement hasn't been implemented yet. This is definitely a great feature to have. Odd that it's in the .NET version, but not in Java.

> Provide a way for not creating items from nested ResultMaps when the items contain only null values
> ---------------------------------------------------------------------------------------------------
>
>                 Key: IBATIS-375
>                 URL: https://issues.apache.org/jira/browse/IBATIS-375
>             Project: iBatis for Java
>          Issue Type: Improvement
>          Components: SQL Maps
>    Affects Versions: 2.2.0
>            Reporter: Stefan Langer
>         Attachments: BasicResultMap.java, BasicResultMapping.java, sql-map-2.dtd, SqlMapParser.java
>
>
> Taken the following resultmaps (uneeded parts are left out) for a simple domainmodel where notebook contains 0 or more pages.
> <resultMap class="notebook" groupBy="id" id="notebookResult">
>    <result column="NB_ID" jdbcType="VARCHAR" property="id"/>
>    <result javaType="java.util.List" property="pages" resultMap="Note.pageResult"/>
> </resultMap>
> <resultMap class="page" groupBy="id" id="pageResult">
>   <result column="P_ID" jdbcType="VARCHAR" property="id"/>
> </resultMap> 
> and the following select statement:
> <select id="selectNotebook" parameterClass="java.lang.String" resultMap="notebookResult">
> SELECT nb.id as nb_id, p.id as p_id,    
> FROM notebook nb LEFT JOIN page p ON nb.id = p.notebook_id
> WHERE nb.id = #id#
> </select> 
> Do to the left join this query will always result in at least one page being created even though the pages are actually empty. 
> It would be nice if the mapping framework could somehow not create these empty objects. 
> The following suggestions come to mind: 
> Either do not create objects where all parameters are null (this indicates the left or right join scenario)
> or provide a way to tag a property in the resultMap which may not be null in order for the object to be created.
> Example:
> <resultMap class="page" groupBy="id" id="pageResult">
>   <result column="P_ID" jdbcType="VARCHAR" property="id" doNotCreateOnNull="true"/>
> </resultMap> 
> This would greatly ease the use of complex mappings where one wants to prevent the dreaded N+1 Select Problem.

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


[jira] Commented: (IBATIS-375) Provide a way for not creating items from nested ResultMaps when the items contain only null values

Posted by "Sylvain Laurent (JIRA)" <ib...@incubator.apache.org>.
    [ https://issues.apache.org/jira/browse/IBATIS-375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12527121 ] 

Sylvain Laurent commented on IBATIS-375:
----------------------------------------

I created a fix for this issue, adopting the solution already applied by iBatis.NET (see https://issues.apache.org/jira/browse/IBATISNET-206)
I added a new attribute "notNullColumn" to the <result> element. If the value of this column is null then the sub object is not created at all.
I attach the files I have modified (from version 2.3.0.677) to the issue.

> Provide a way for not creating items from nested ResultMaps when the items contain only null values
> ---------------------------------------------------------------------------------------------------
>
>                 Key: IBATIS-375
>                 URL: https://issues.apache.org/jira/browse/IBATIS-375
>             Project: iBatis for Java
>          Issue Type: Improvement
>          Components: SQL Maps
>    Affects Versions: 2.2.0
>            Reporter: Stefan Langer
>
> Taken the following resultmaps (uneeded parts are left out) for a simple domainmodel where notebook contains 0 or more pages.
> <resultMap class="notebook" groupBy="id" id="notebookResult">
>    <result column="NB_ID" jdbcType="VARCHAR" property="id"/>
>    <result javaType="java.util.List" property="pages" resultMap="Note.pageResult"/>
> </resultMap>
> <resultMap class="page" groupBy="id" id="pageResult">
>   <result column="P_ID" jdbcType="VARCHAR" property="id"/>
> </resultMap> 
> and the following select statement:
> <select id="selectNotebook" parameterClass="java.lang.String" resultMap="notebookResult">
> SELECT nb.id as nb_id, p.id as p_id,    
> FROM notebook nb LEFT JOIN page p ON nb.id = p.notebook_id
> WHERE nb.id = #id#
> </select> 
> Do to the left join this query will always result in at least one page being created even though the pages are actually empty. 
> It would be nice if the mapping framework could somehow not create these empty objects. 
> The following suggestions come to mind: 
> Either do not create objects where all parameters are null (this indicates the left or right join scenario)
> or provide a way to tag a property in the resultMap which may not be null in order for the object to be created.
> Example:
> <resultMap class="page" groupBy="id" id="pageResult">
>   <result column="P_ID" jdbcType="VARCHAR" property="id" doNotCreateOnNull="true"/>
> </resultMap> 
> This would greatly ease the use of complex mappings where one wants to prevent the dreaded N+1 Select Problem.

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