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 Warren <wa...@clarksnutrition.com> on 2006/11/28 04:17:43 UTC

Another n+1 Question NullPointerException

I am getting the following error messages when running an SQL Map:

com.ibatis.dao.client.DaoException:
Error executing query for list.
--- The error occurred while applying a result map.
--- Check the Item.batchedItemPromoResults.
--- Check the result mapping for the 'promoPrices' property.
--- Cause: java.lang.NullPointerException

My SQL map:

  <resultMap id="batchedItemPromoResults" class="batchedItemPromos" 
groupBy="item.upc" >
    <result property="item.invPK" column="INV_PK"  jdbcType="INTEGER" 
nullValue="0"/>
    <result property="item.invCPK" column="INV_CPK"  jdbcType="INTEGER" 
nullValue="0"/>
    <result property="item.upc" column="INV_ScanCode" javaType="string" 
jdbcType="CHAR" nullValue="NULL"/>
    <result property="promoPrices" resultMap="batchedPromoPrices" />
  </resultMap>
   
  <resultMap id="batchedPromoPrices" class="promoPrice" >
    <result property="description" column="PCD_WRKName" 
javaType="string" jdbcType="CHAR" nullValue="NULL"/>
  </resultMap>


    <select id="getBatchedItemPromoPrices" 
resultMap="batchedItemPromoResults">
     SELECT INV_PK, INV_CPK, INV_ScanCode, PCD_WRKName FROM 
PriceChangeData, v_InventoryMaster, PromotionalSaleWorkSheet, Worksheets 
WHERE INV_PK = PCD_INV_FK AND INV_CPK = PCD_INV_CFK AND PCD_PSW_FK = 
PSW_PK AND PCD_PSW_CFK = PSW_CPK AND PSW_WRK_FK = WRK_PK AND PSW_WRK_CFK 
= WRK_CPK AND INV_ScanCode = '65801011111   ' AND PCD_Permanent = 0
    </select>

My Objects:

batchedItemPromos with properties
Item item;
List promoPrices;

item with properties
invPK int;
invCPK int;
upc String;

promoPrice with properties
description String;

The static query I am using is for testing and it returns one record. 
How am I getting a NullPointerException? What am I doing wrong?

Thanks,

Warren


Re: Another n+1 Question NullPointerException

Posted by "Eric T. Blue" <er...@gmail.com>.
Warren,

I believe you'll need to initialize promoPrices on declaration or in the
constructor.

List promoPrices = new ArrayList();

On 11/27/06, Warren <wa...@clarksnutrition.com> wrote:
>
> I am getting the following error messages when running an SQL Map:
>
> com.ibatis.dao.client.DaoException:
> Error executing query for list.
> --- The error occurred while applying a result map.
> --- Check the Item.batchedItemPromoResults.
> --- Check the result mapping for the 'promoPrices' property.
> --- Cause: java.lang.NullPointerException
>
> My SQL map:
>
>   <resultMap id="batchedItemPromoResults" class="batchedItemPromos"
> groupBy="item.upc" >
>     <result property="item.invPK" column="INV_PK"  jdbcType="INTEGER"
> nullValue="0"/>
>     <result property="item.invCPK" column="INV_CPK"  jdbcType="INTEGER"
> nullValue="0"/>
>     <result property="item.upc" column="INV_ScanCode" javaType="string"
> jdbcType="CHAR" nullValue="NULL"/>
>     <result property="promoPrices" resultMap="batchedPromoPrices" />
>   </resultMap>
>
>   <resultMap id="batchedPromoPrices" class="promoPrice" >
>     <result property="description" column="PCD_WRKName"
> javaType="string" jdbcType="CHAR" nullValue="NULL"/>
>   </resultMap>
>
>
>     <select id="getBatchedItemPromoPrices"
> resultMap="batchedItemPromoResults">
>      SELECT INV_PK, INV_CPK, INV_ScanCode, PCD_WRKName FROM
> PriceChangeData, v_InventoryMaster, PromotionalSaleWorkSheet, Worksheets
> WHERE INV_PK = PCD_INV_FK AND INV_CPK = PCD_INV_CFK AND PCD_PSW_FK =
> PSW_PK AND PCD_PSW_CFK = PSW_CPK AND PSW_WRK_FK = WRK_PK AND PSW_WRK_CFK
> = WRK_CPK AND INV_ScanCode = '65801011111   ' AND PCD_Permanent = 0
>     </select>
>
> My Objects:
>
> batchedItemPromos with properties
> Item item;
> List promoPrices;
>
> item with properties
> invPK int;
> invCPK int;
> upc String;
>
> promoPrice with properties
> description String;
>
> The static query I am using is for testing and it returns one record.
> How am I getting a NullPointerException? What am I doing wrong?
>
> Thanks,
>
> Warren
>
>