Caused by: com.ibatis.dao.client.DaoException: Error executing query for list. Cause: com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in com/clarks/spanky/persistence/sqlmapdao/sql/postgres/batchOrder-postgres.xml. --- The error occurred while applying a result map. --- Check the BatchOrder.catItemsResults. --- Check the result mapping for the 'items' property. --- Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in com/clarks/spanky/persistence/sqlmapdao/sql/postgres/batchOrder-postgres.xml. --- The error occurred while applying a result map. --- Check the BatchOrder.catItemsResults. --- Check the result mapping for the 'items' property. --- Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
at com.clarks.spanky.persistence.sqlmapdao.BaseSqlMapDao.executeQueryForList(BaseSqlMapDao.java:35) at com.clarks.spanky.persistence.sqlmapdao.BatchOrderSqlMapDao.getBatchedItemPromoPrices(BatchOrderSqlMapDao.java:270)
   ... 34 more
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in com/clarks/spanky/persistence/sqlmapdao/sql/postgres/batchOrder-postgres.xml. --- The error occurred while applying a result map. --- Check the BatchOrder.catItemsResults. --- Check the result mapping for the 'items' property. --- Cause: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:155) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:95) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:247) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:232) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:71) at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:49) at com.clarks.spanky.persistence.sqlmapdao.BaseSqlMapDao.executeQueryForList(BaseSqlMapDao.java:32)
   ... 35 more
Caused by: java.lang.NullPointerException
at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMappingValue(BasicResultMap.java:268) at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getResults(BasicResultMap.java:107) at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:274) at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:125) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:172) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:139)
   ... 41 more


Jeff Butler wrote:
Sorry for your frustration, but you'll have to tell us where the NullPointerException is coming from. Could you post a stack trace? Jeff Butler

On 12/1/06, *Warren* <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Stefan Langer wrote:
    > Warren wrote:
    >> I am having problems with an n+1 sql map. I am getting the
    following
    >> error messages:
    >>
    >> --- The error occurred while applying a result map. --- Check the
    >> CatItem.catItemsResults. --- Check the result mapping for the
    'items'
    >> property. --- Cause: java.lang.NullPointerException
    >>
    >> I have put the following test together:
    >>
    >> Objects
    >>
    >> TestCat object
    >>
    >> private int catPK;
    >> private String catName;
    >> private List items;
    >>
    >> TestItem object
    >>
    >> private int itemPK;
    >> private String itemName;
    >>
    >> Database Tables
    >>
    >> testitem table
    >>
    >> itm_pk int4,
    >> itm_cat_fk int4,
    >> itm_name char(20),
    >>
    >> testcat table
    >>
    >> cat_pk int4,
    >> cat_name char(20)
    >>
    >> <resultMap id="catItemsResults" class="testCat" groupBy="catPK" >
    >>   <result property="catPK" column="cat_pk" javaType="int"
    >> jdbcType="INTEGER"/>
    >>   <result property="catName" column="cat_name" javaType="string"
    >> jdbcType="CHAR"/>
    >>   <result property="items" javaType="java.util.List"
    >> resultMap="CatItem.itemsResults" />
    >> </resultMap>
    >>   <resultMap id="itemsResults" class="testItem" >
    >>  <result property="itemName" column="itm_name" javaType="string"
    >> jdbcType="CHAR"/>
    >> </resultMap>
    >>
    >> <select id="getCatWithItems" resultMap="catItemsResults"
    >>  SELECT cat_pk, cat_name, itm_name FROM testcat LEFT JOIN
    testitem ON
    >> cat_pk = itm_cat_fk
    >> </select>
    >>
    >> I have looked at the FAQ, docs and mailing list archive and I
    can not
    >> figure out what I am doing wrong. I have tried it on a Postgres db
    >> with a postgres driver and a Sybase db with an ODBC driver. I still
    >> get the same results. I am running version 2.1.7 of Ibatis.
    What am I
    >> doing wrong?
    >>
    >> Thanks,
    >>
    >> Warren
    > Where does the nullpointer occur? In your code or in ibatis code?
    > When you run your query you will have a item in your items map even
    > though the testCat does not contain any testItem. This item will
    have
    > all null values. So if any of the methods in testItem throw a
    > nullpointerexception when being fed with a null value that will
    > probably be the case.
    >
    > I just filed an enhancement request for Ibatis to prevent ibatis
    from
    > creating such null objects. Feel free to vote or comment on it.
    > The issue is: IBATIS-375
    The null pointer occurs in:

    sqlMap.queryForList(statementName, parameterObject)

    I should get a List of TestCat objects with a List of TestItems,
    shouldn't I? I couldn't quite follow your explanation of how
    TestCat and
    the items List are being populated. I think I understand that if a
    testCat does not have any testItems, the items List in testCat will
    still have a testItem in it with it's properties set to null, correct?
    But my query does not return any testCats without a testItem in it. My
    object setters are all very simple:

    public void setCatName(String catName)
    {
       this.catName = catName;
    }

    When I set the loggers to DEBUG I get the following log entries:

    DEBUG [http-8080-Processor24] - Checked out connection 2100665
    from pool.
    DEBUG [http-8080-Processor24] - {conn-100186} Connection
    DEBUG [http-8080-Processor24] - {pstm-100187} PreparedStatement:
    SELECT cat_pk, itm_pk, cat_name, itm_name FROM testcat LEFT JOIN
    testitem ON cat_pk = itm_cat_fk
    DEBUG [http-8080-Processor24] - {pstm-100187} Parameters: []
    DEBUG [http-8080-Processor24] - {pstm-100187} Types: []
    DEBUG [http-8080-Processor24] - {rset-100188} ResultSet
    getBatchedItemDetails(Object batchedItems)
    EXCEPTION=com.ibatis.dao.client.DaoException: IBATIS PROBLEM Error
    executing query for list.  Cause:
    com.ibatis.common.jdbc.exception.NestedSQLException:
    --- The error occurred in
    
com/clarks/spanky/persistence/sqlmapdao/sql/postgres/batchOrder-postgres.xml.

    --- The error occurred while applying a result map.
    --- Check the BatchOrder.catItemsResults.
    --- Check the result mapping for the 'items' property.
    --- Cause: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException
    Caused by: com.ibatis.common.jdbc.exception.NestedSQLException :
    --- The error occurred in
    
com/clarks/spanky/persistence/sqlmapdao/sql/postgres/batchOrder-postgres.xml.

    --- The error occurred while applying a result map.
    --- Check the BatchOrder.catItemsResults.
    --- Check the result mapping for the 'items' property.
    --- Cause: java.lang.NullPointerException
    Caused by: java.lang.NullPointerException
    DEBUG [http-8080-Processor24] - Returned connection 2100665 to pool.

    Is this telling me that the SELECT is not returning any records? I
    get
    the following results when I run the above logged SELECT directly
    on the db:

    The SELECT query returns:

    ** cat_pk       cat_name        itm_name
    1       Vitamins        Vitamin Item 3
    1       Vitamins        Vitamin Item 1
    1       Vitamins        Vitamin Item 2
    2       Herbs   Herbs Item 3
    2       Herbs   Herbs Item 2
    2       Herbs   Herbs Item 1
    2       Herbs   Herbs Item 4
    3       Groceries       Grocery Item 2
    3       Groceries       Grocery Item 3
    3       Groceries       Grocery Item 1


    This is on a Postgres db with a postgres driver. I have also
    changed the
    sqlMap to the following and I still get the same exception:

    <resultMap id="catItemsResults" class="testCat" groupBy="catPK" >
      <result property="catPK" column="cat_pk" javaType="int"
    jdbcType="NUMERIC" nullValue="0"/>
    <result property="catName" column="cat_name" javaType="string"
    jdbcType="CHAR" nullValue="NULL"/>
    <result property="items" javaType="java.util.List"
    resultMap="CatItem.itemsResults" />
    </resultMap>

    <resultMap id="itemsResults" class="testItem" >
       <result property="itemPK" column="itm_pk" javaType="int"
    jdbcType="NUMERIC" nullValue="0"/>
       <result property="itemName" column="itm_name" javaType="string"
    jdbcType="CHAR" nullValue="NULL"/>
    </resultMap>

    <select id="getBatchedItemPromoPrices" resultMap="catItemsResults">
      SELECT cat_pk, itm_pk, cat_name, itm_name FROM testcat LEFT JOIN
    testitem ON cat_pk = itm_cat_fk
    </select>

    Where is the NullPointerException coming from? I am not very
    experienced
    with Ibatis and do not know what is going on behind the scenes.
    This is
    all very frustrating.



Reply via email to