You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Jakub Vondrak <id...@centrum.cz> on 2010/02/20 21:21:23 UTC

performance issue for id as association

Hello,

I'm new to iBatis 3 so maybe I'm overooking something obvious, but I'm
having problem while trying to map id object as association.

Here is my result map

   <resultMap id="billResultMap" type="Bill">
      <id column="bill_id" property="id" />
      <collection property="billItems" ofType="BillItem">
          <result column="bi_sku" property="customId" />
          <result column="bi_name" property="name" />
          ...

         <association property="id" javaType="BillItemId">
            <id column="bill_id" property="idBill"/>
            <id column="bill_id" property="itemOrder" />
         </association>
      </collection>
   </resultMap>

Problem is that class BillItem has another class BillItemId which acts
as ID, but I'm not able to express this fact in result map.
This is probably the reason why I'm having performance problems
(java.lang.OutOfMemoryError: Java heap space).

Can anybody help?

Thanks and regards,
Jakub

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: performance issue for id as association

Posted by Jakub Vondrak <id...@centrum.cz>.
Jakub Vondrak wrote:
> Guy Rouillier wrote:
>> On 2/20/2010 3:21 PM, Jakub Vondrak wrote:
>>> Hello,
>>>
>>> I'm new to iBatis 3 so maybe I'm overooking something obvious, but I'm
>>> having problem while trying to map id object as association.
>>>
>>> Here is my result map
>>>
>>>     <resultMap id="billResultMap" type="Bill">
>>>        <id column="bill_id" property="id" />
>>>        <collection property="billItems" ofType="BillItem">
>>>            <result column="bi_sku" property="customId" />
>>>            <result column="bi_name" property="name" />
>>>            ...
>>>
>>>           <association property="id" javaType="BillItemId">
>>>              <id column="bill_id" property="idBill"/>
>>>              <id column="bill_id" property="itemOrder" />
>>>           </association>
>>>        </collection>
>>>     </resultMap>
>>>
>>> Problem is that class BillItem has another class BillItemId which acts
>>> as ID, but I'm not able to express this fact in result map.
>>> This is probably the reason why I'm having performance problems
>>> (java.lang.OutOfMemoryError: Java heap space).
>>>
>> That's not a performance problem, that's an out-of-memory problem.  You
>> probably have a circular reference.  Take a look in the User Guide PDF
>> in the section titled Advanced Result Mapping.  It has an example using
>> an association.  An association is a 1-to-1 mapping.  Your example above
>> doesn't identify a column on which to establish the association.  It
>> also lists two <id> entries, both for the same source column.  That
>> can't be right.
>>
> Thanks for the answer. If I reduce returned record count, I don't get
> OutOfMemory, but I'm still not able to do what I need in mapping and I
> guess that OutOfMemory exception is related to it.
> 
> First let me give you more information:
> 
> DB schema looks like this:
> 
> CREATE TABLE BILL(
>     ID INTEGER NOT NULL PRIMARY KEY
> )
> 
> CREATE TABLE BILL_ITEM(
>     ID_BILL INTEGER NOT NULL,
>     ITEM_ORDER INTEGER NOT NULL,
>     SKU VARCHAR(255),
>     NAME VARCHAR(255),
>     PRIMARY KEY(ID_BILL,ITEM_ORDER),
>     CONSTRAINT BILL FOREIGN KEY(ID_BILL) REFERENCES BILL(ID)
> )
> 
> Mapping for select looks like this:
>    <select id="selectAll" resultMap="billResultMap">
>       select
>       B.id as bill_id,
>       BI.item_order as bi_item_order,
>       BI.sku as bi_sku,
>       BI.name as bi_name,
>       from bill B
>       left outer join bill_item BI on B.id = BI.id_bill
>    </select>
> 
> What I guess is the problem is that I cannot express *composite key as
> an BillItemId object* on the BillItem class and I guess I will need own
> TypeHandler for whole Bill class.
> 
> I was expecting, that something like:
> <id property="id" column="{idBill=bill_id, itemOrder=bi_item_order}"
> javaType="BillItemId"/>
> is possible, but it doesn't seem so.
> 
> Every combination I have tried yields following errors:
> 1) there is just one BillItem for each Bill
> 2) BillItemId for every BillItem is null
> 
I have found the answer in another thread on this mailing list. I just
didn't realize proper wording for searching earlier.

Composite properties can be mapped with "dot notation" like this:

   <resultMap id="billResultMap" type="Bill">
      <id column="bill_id" property="id" />
      <collection property="billItems" ofType="BillItem">
          <id property="id.idBill" column="bill_id"/>
          <id property="id.itemOrder" column="bi_item_order" />

          <result column="bi_sku" property="customId" />
          <result column="bi_name" property="name" />
      </collection>
   </resultMap>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: performance issue for id as association

Posted by Guy Rouillier <gu...@burntmail.com>.
On 2/22/2010 2:35 AM, Jakub Vondrak wrote:

>> The separate BillItemId class is unnecessary.
>>
> Yes it is unnecessary for iBatis. The reason why this class exists is
> that the model was created to suite Hibernate several years ago.
>
> I'm trying to convert data layer to iBatis and retain a compatible
> model. Then I would like to compare performance and ease of use.

Ok, this works:

<resultMap id="BillItemNestedMap" type="com.ibatisdemo.db.Bill" >
     <id column="bill_id" property="id" jdbcType="INTEGER" />
     <collection column="bi_item_order" property="billItems" 
javaType="ArrayList" ofType="com.ibatisdemo.db.BillItem">
        <id column="bill_id" property="idBill" jdbcType="INTEGER" />
        <id column="bi_item_order" property="itemOrder" 
jdbcType="INTEGER" />
        <result column="bi_sku" property="sku" jdbcType="VARCHAR" />
        <result column="bi_name" property="name" jdbcType="VARCHAR" />
        <association column="bi_item_order" property="billItemKey" 
javaType="com.ibatisdemo.db.BillItemKey">
           <id column="bill_id" property="idBill"/>
           <id column="bi_item_order" property="itemOrder" />
        </association>
     </collection>
</resultMap>


The two columns from BillItemKey are also in BillItem because I used 
Ibator to generate the classes.

-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: performance issue for id as association

Posted by Jakub Vondrak <id...@centrum.cz>.
Guy Rouillier wrote:
> On 2/21/2010 6:15 AM, Jakub Vondrak wrote:
> 
>>>>      <resultMap id="billResultMap" type="Bill">
>>>>         <id column="bill_id" property="id" />
>>>>         <collection property="billItems" ofType="BillItem">
>>>>             <result column="bi_sku" property="customId" />
>>>>             <result column="bi_name" property="name" />
>>>>             ...
>>>>
>>>>            <association property="id" javaType="BillItemId">
>>>>               <id column="bill_id" property="idBill"/>
>>>>               <id column="bill_id" property="itemOrder" />
>>>>            </association>
>>>>         </collection>
>>>>      </resultMap>
> 
>> What I guess is the problem is that I cannot express *composite key as
>> an BillItemId object* on the BillItem class and I guess I will need own
>> TypeHandler for whole Bill class.
> 
> This works for me:
> 
> <resultMap id="billResultMap" type="Bill">
>    <id column="bill_id" property="id" />
>    <collection property="billItems" javaType="ArrayList" ofType="BillItem">
>        <id column="bill_id" property="idBill"/>
>        <id column="bi_item_order" property="itemOrder" />
>        <result column="bi_sku" property="customId" />
>        <result column="bi_name" property="name" />
>        ...
> 
>    </collection>
> </resultMap>
> 
> The separate BillItemId class is unnecessary.
> 
Yes it is unnecessary for iBatis. The reason why this class exists is
that the model was created to suite Hibernate several years ago.

I'm trying to convert data layer to iBatis and retain a compatible
model. Then I would like to compare performance and ease of use.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: performance issue for id as association

Posted by Guy Rouillier <gu...@burntmail.com>.
On 2/21/2010 6:15 AM, Jakub Vondrak wrote:

>>>      <resultMap id="billResultMap" type="Bill">
>>>         <id column="bill_id" property="id" />
>>>         <collection property="billItems" ofType="BillItem">
>>>             <result column="bi_sku" property="customId" />
>>>             <result column="bi_name" property="name" />
>>>             ...
>>>
>>>            <association property="id" javaType="BillItemId">
>>>               <id column="bill_id" property="idBill"/>
>>>               <id column="bill_id" property="itemOrder" />
>>>            </association>
>>>         </collection>
>>>      </resultMap>

> What I guess is the problem is that I cannot express *composite key as
> an BillItemId object* on the BillItem class and I guess I will need own
> TypeHandler for whole Bill class.

This works for me:

<resultMap id="billResultMap" type="Bill">
    <id column="bill_id" property="id" />
    <collection property="billItems" javaType="ArrayList" ofType="BillItem">
        <id column="bill_id" property="idBill"/>
        <id column="bi_item_order" property="itemOrder" />
        <result column="bi_sku" property="customId" />
        <result column="bi_name" property="name" />
        ...

    </collection>
</resultMap>

The separate BillItemId class is unnecessary.

-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: performance issue for id as association

Posted by Jakub Vondrak <id...@centrum.cz>.
Guy Rouillier wrote:
> On 2/20/2010 3:21 PM, Jakub Vondrak wrote:
>> Hello,
>>
>> I'm new to iBatis 3 so maybe I'm overooking something obvious, but I'm
>> having problem while trying to map id object as association.
>>
>> Here is my result map
>>
>>     <resultMap id="billResultMap" type="Bill">
>>        <id column="bill_id" property="id" />
>>        <collection property="billItems" ofType="BillItem">
>>            <result column="bi_sku" property="customId" />
>>            <result column="bi_name" property="name" />
>>            ...
>>
>>           <association property="id" javaType="BillItemId">
>>              <id column="bill_id" property="idBill"/>
>>              <id column="bill_id" property="itemOrder" />
>>           </association>
>>        </collection>
>>     </resultMap>
>>
>> Problem is that class BillItem has another class BillItemId which acts
>> as ID, but I'm not able to express this fact in result map.
>> This is probably the reason why I'm having performance problems
>> (java.lang.OutOfMemoryError: Java heap space).
>>
> 
> That's not a performance problem, that's an out-of-memory problem.  You
> probably have a circular reference.  Take a look in the User Guide PDF
> in the section titled Advanced Result Mapping.  It has an example using
> an association.  An association is a 1-to-1 mapping.  Your example above
> doesn't identify a column on which to establish the association.  It
> also lists two <id> entries, both for the same source column.  That
> can't be right.
> 
Thanks for the answer. If I reduce returned record count, I don't get
OutOfMemory, but I'm still not able to do what I need in mapping and I
guess that OutOfMemory exception is related to it.

First let me give you more information:

DB schema looks like this:

CREATE TABLE BILL(
    ID INTEGER NOT NULL PRIMARY KEY
)

CREATE TABLE BILL_ITEM(
    ID_BILL INTEGER NOT NULL,
    ITEM_ORDER INTEGER NOT NULL,
    SKU VARCHAR(255),
    NAME VARCHAR(255),
    PRIMARY KEY(ID_BILL,ITEM_ORDER),
    CONSTRAINT BILL FOREIGN KEY(ID_BILL) REFERENCES BILL(ID)
)

Mapping for select looks like this:
   <select id="selectAll" resultMap="billResultMap">
      select
      B.id as bill_id,
      BI.item_order as bi_item_order,
      BI.sku as bi_sku,
      BI.name as bi_name,
      from bill B
      left outer join bill_item BI on B.id = BI.id_bill
   </select>

What I guess is the problem is that I cannot express *composite key as
an BillItemId object* on the BillItem class and I guess I will need own
TypeHandler for whole Bill class.

I was expecting, that something like:
<id property="id" column="{idBill=bill_id, itemOrder=bi_item_order}"
javaType="BillItemId"/>
is possible, but it doesn't seem so.

Every combination I have tried yields following errors:
1) there is just one BillItem for each Bill
2) BillItemId for every BillItem is null

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Re: performance issue for id as association

Posted by Guy Rouillier <gu...@burntmail.com>.
On 2/20/2010 3:21 PM, Jakub Vondrak wrote:
> Hello,
>
> I'm new to iBatis 3 so maybe I'm overooking something obvious, but I'm
> having problem while trying to map id object as association.
>
> Here is my result map
>
>     <resultMap id="billResultMap" type="Bill">
>        <id column="bill_id" property="id" />
>        <collection property="billItems" ofType="BillItem">
>            <result column="bi_sku" property="customId" />
>            <result column="bi_name" property="name" />
>            ...
>
>           <association property="id" javaType="BillItemId">
>              <id column="bill_id" property="idBill"/>
>              <id column="bill_id" property="itemOrder" />
>           </association>
>        </collection>
>     </resultMap>
>
> Problem is that class BillItem has another class BillItemId which acts
> as ID, but I'm not able to express this fact in result map.
> This is probably the reason why I'm having performance problems
> (java.lang.OutOfMemoryError: Java heap space).
>

That's not a performance problem, that's an out-of-memory problem.  You 
probably have a circular reference.  Take a look in the User Guide PDF 
in the section titled Advanced Result Mapping.  It has an example using 
an association.  An association is a 1-to-1 mapping.  Your example above 
doesn't identify a column on which to establish the association.  It 
also lists two <id> entries, both for the same source column.  That 
can't be right.

-- 
Guy Rouillier

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org