Hi folks,
again me (seems that I am touching all the rather complicated topics of iBatis
during my very first project).
The problem is appearing while I try to avoid an N+1 select for a 1:M
relationship (as described on p. 36 in the latest developer guide).
I think that I may be using the groupBy attribute in an incorrect way but I am
not sure how it has to be done correctly. (I tried using groupBy="ID" as well
as groupBy="id" but that returned the same error).
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in global/persistence/mom/MOM_SqlMap.xml.
--- The error occurred while applying a result map.
--- Check the MOM.r_getCustomerOrder.
--- The error happened while setting a property on the result object.
--- Cause: com.ibatis.common.beans.ProbeException: Could not set property
'customerOrderItemsList' for global.persistence.mom.CustomerOrderMapper.
Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
Caused by: com.ibatis.common.beans.ProbeException: Could not set property
'customerOrderItemsList' for global.persistence.mom.CustomerOrderMapper.
Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:561)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:536)
at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:93)
at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:70)
//The mapping
<resultMap id="r_getCustomerOrder" class="CustomerOrderMapper"
groupBy="orderItemKey.articleKey.articleId">
<result property="objectId" column="ID" />
<result property="comment" column="COMMENT" />
<result property="mom" column="IS_MOM" />
<result property="kimStatus" column="KIMSTATUS" />
<result property="customerOrderKey.customerId"
column="CUSTOMER_ID" />
<result property="customerOrderKey.orderId" column="ORDERID" />
<result property="customerOrderKey.version" column="VERSION" />
<result property="customerOrderKey.moduleKey.moduleId"
column="MODULE_ID" />
<result property="customerOrderKey.collectionKey.seasonId"
column="SAISON" />
<!-- <result
property="customerOrderKey.collectionKey.collectionCategoryId" column="SEGMENT"
/> not existant within MOM-->
<result property="customerOrderKey.collectionKey.segmentId"
column="SEGMENT" />
<!-- <result property="customerOrderItemsList" column="{id=ID}"
select="getCustomerOrderItem" /> -->
<result property="customerOrderItemsList"
resultMap="MOM.r_getCustomerOrderItem" />
</resultMap>
<resultMap id="r_getOrderItemBase" class="OrderItemBase">
<!-- <result property="objectId" column="" /> -->
<!-- <result property="salesPrice" column="" /> -->
<!-- <result property="recommendedRetailPrice" column="" /> -->
<!-- <result property="currency" column="" /> -->
<result property="orderItemKey.articleKey.articleId"
column="ARTICLE_NUM" />
<result
property="orderItemKey.articleColourKey.articleColourId" column="COLOUR" />
</resultMap>
<resultMap id="r_getOrderItem" class="OrderItem"
extends="r_getOrderItemBase">
<result property="orderedQuantity" column="ORDERED_QUANTITY"/>
</resultMap>
<resultMap id="r_getCustomerOrderItem" class="CustomerOrderItem"
extends="r_getOrderItem">
<result property="size" column="ARTICLE_SIZE" />
<result property="length" column="ARTICLE_LENGTH" />
</resultMap>
//The query
SELECT c.ID, c.COMMENT, c.KIMSTATUS, c.CUSTOMER_ID,
c.ORDERID, c.VERSION, c.MODULE_ID, c.SAISON, c.SEGMENT, c.IS_MOM,
a.ARTICLE_NUM, d.COLOUR, d.ORDERED_QUANTITY,e.ARTICLE_SIZE, e.ARTICLE_LENGTH
FROM
MENU.ARTICLE a inner join
MENU.ARTICLE2MENUORDER b on a.ARTICLE_NUM=b.ARTICLE_NUM
inner join MENU.MENUORDER c on b.MENUORDER_ID=c.ID
left outer join MENU.COLOUR2ARTICLE d on d.ART2MO_ID=b.ID
left outer join MENU.SIZE2ARTICLE e on d.ART2MO_ID=b.ID
WHERE
c.ID=#objectId#
//Customer Order is providing only methods access an Array, thus the Wrapper. I
have provided this class in order to allow you to ensure that I am not missing
anything in here.
public class CustomerOrderMapper extends CustomerOrder {
public void setCustomerOrderItemsList(List pCustomerOrderItemList) {
if (pCustomerOrderItemList.size() > 0) {
CustomerOrderItem[] coi= (CustomerOrderItem[])
pCustomerOrderItemList.toArray(new
CustomerOrderItem[pCustomerOrderItemList.size()]);
setCustomerOrderItems(coi);
}
}
public List getCustomerOrderItemsList() {
if(getCustomerOrderItems()==null)
{
return new ArrayList();
}
else
{
return Arrays.asList(getCustomerOrderItems());
}
}
}
--
Gruß
Torsten Michelmann
"Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail