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/12/01 04:32:12 UTC
n+1 Problem NullPointerException
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
Re: n+1 Problem NullPointerException
Posted by Warren <wa...@clarksnutrition.com>.
I have initialized my properties as follows:
testItem
private int itemPK = 0;
private String itemName = "";
testCat
private int catPK = 0;
private String catName = "";
private List items = new ArrayList();
> 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* <warren@clarksnutrition.com
>> <ma...@clarksnutrition.com>> 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.
>>
>>
Re: n+1 Problem NullPointerException
Posted by Warren <wa...@clarksnutrition.com>.
Jeff,
I think you were write about the older version. I had quite a lot of
them sitting around. I have since deleted them and cleaned up my
classpath, but in the process it has broken my code. So, I can not test
whether that was the problem or not write at this time. I am in the
process of fixing things using the latest version, but it is probably
safe to say the older versions were messing things up. Sorry about all
the shadow chasing, I appreciate the help everyone has given me. This is
truly one of the more helpful mailing lists I have used.
Clinton Begin wrote:
> Once you guys have figured out whether it's a primitive mapping
> problem and the correct stack trace/line numbers...let me know.
>
> If it is an iBATIS problem, I'll give you a hand looking for the
> issue. The N+1 stuff is a bit tough to navigate.
>
> I am always embarassed when an NPE is thrown...there's no good excuse
> for it. So I really hope its not the iBATIS code. ;-)
>
> Regards,
> Clinton
>
>
> On 12/4/06, * Jeff Butler* <jeffgbutler@gmail.com
> <ma...@gmail.com>> wrote:
>
> Something is very odd. The line numbers in the stack trace are
> nowhere near the current line numbers - I had to go back over 2
> years to find a match. So I think part of the problem is that
> there is a really old version of iBATIS somewhere in your classpath.
>
> Please make sure that you are using a current version of iBATIS,
> and that all old version are removed from the classpath. That
> should help a lot!
>
> Jeff Butler
>
>
>
> On 12/4/06, *Warren* <warren@clarksnutrition.com
> <ma...@clarksnutrition.com>> wrote:
>
> I tried changing the int properties to Integer and I am still
> getting
> the same exceptions. I guess it is time to give up. Thanks for
> everyones
> help.
>
> Warren wrote:
> > I will give it a try. I don't seem to have this problem with
> other
> > sqlMaps I am using. This is the first n+1 I have tried. Is
> this the
> > Exception that leads you to believe that it is a primitive
> mapping
> > problem:
> >
> > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMappingValue(BasicResultMap.java:268)
> >
> >
> > Jeff Butler wrote:
> >> Thanks for the stack trace.
> >>
> >> I'll have to look into this a little further. iBATIS is a
> little
> >> finicky when it comes to using primitive types. You might have
> >> better luck if you changed to using Integer instead of int
> for the
> >> primary keys.
> >>
> >> Jeff Butler
> >>
> >>
> >> On 12/1/06, *Warren* < warren@clarksnutrition.com
> <ma...@clarksnutrition.com>
> >> <mailto: warren@clarksnutrition.com
> <ma...@clarksnutrition.com>>> wrote:
> >>
> >> 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
> >> >
> >>
>
>
>
Re: n+1 Problem NullPointerException
Posted by Clinton Begin <cl...@gmail.com>.
Once you guys have figured out whether it's a primitive mapping problem and
the correct stack trace/line numbers...let me know.
If it is an iBATIS problem, I'll give you a hand looking for the issue. The
N+1 stuff is a bit tough to navigate.
I am always embarassed when an NPE is thrown...there's no good excuse for
it. So I really hope its not the iBATIS code. ;-)
Regards,
Clinton
On 12/4/06, Jeff Butler <je...@gmail.com> wrote:
>
> Something is very odd. The line numbers in the stack trace are nowhere
> near the current line numbers - I had to go back over 2 years to find a
> match. So I think part of the problem is that there is a really old version
> of iBATIS somewhere in your classpath.
>
> Please make sure that you are using a current version of iBATIS, and that
> all old version are removed from the classpath. That should help a lot!
>
> Jeff Butler
>
>
>
> On 12/4/06, Warren <wa...@clarksnutrition.com> wrote:
> >
> > I tried changing the int properties to Integer and I am still getting
> > the same exceptions. I guess it is time to give up. Thanks for everyones
> >
> > help.
> >
> > Warren wrote:
> > > I will give it a try. I don't seem to have this problem with other
> > > sqlMaps I am using. This is the first n+1 I have tried. Is this the
> > > Exception that leads you to believe that it is a primitive mapping
> > > problem:
> > >
> > >
> > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMappingValue
> > (BasicResultMap.java:268)
> > >
> > >
> > > Jeff Butler wrote:
> > >> Thanks for the stack trace.
> > >>
> > >> I'll have to look into this a little further. iBATIS is a little
> > >> finicky when it comes to using primitive types. You might have
> > >> better luck if you changed to using Integer instead of int for the
> > >> primary keys.
> > >>
> > >> Jeff Butler
> > >>
> > >>
> > >> On 12/1/06, *Warren* <warren@clarksnutrition.com
> > >> <mailto: warren@clarksnutrition.com>> wrote:
> > >>
> > >> 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
> > >> >
> > >>
> >
> >
>
Re: n+1 Problem NullPointerException
Posted by Jeff Butler <je...@gmail.com>.
Something is very odd. The line numbers in the stack trace are nowhere near
the current line numbers - I had to go back over 2 years to find a match.
So I think part of the problem is that there is a really old version of
iBATIS somewhere in your classpath.
Please make sure that you are using a current version of iBATIS, and that
all old version are removed from the classpath. That should help a lot!
Jeff Butler
On 12/4/06, Warren <wa...@clarksnutrition.com> wrote:
>
> I tried changing the int properties to Integer and I am still getting
> the same exceptions. I guess it is time to give up. Thanks for everyones
> help.
>
> Warren wrote:
> > I will give it a try. I don't seem to have this problem with other
> > sqlMaps I am using. This is the first n+1 I have tried. Is this the
> > Exception that leads you to believe that it is a primitive mapping
> > problem:
> >
> >
> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMappingValue
> (BasicResultMap.java:268)
> >
> >
> > Jeff Butler wrote:
> >> Thanks for the stack trace.
> >>
> >> I'll have to look into this a little further. iBATIS is a little
> >> finicky when it comes to using primitive types. You might have
> >> better luck if you changed to using Integer instead of int for the
> >> primary keys.
> >>
> >> Jeff Butler
> >>
> >>
> >> On 12/1/06, *Warren* <warren@clarksnutrition.com
> >> <ma...@clarksnutrition.com>> wrote:
> >>
> >> 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
> >> >
> >>
>
>
Re: n+1 Problem NullPointerException
Posted by Richard Yee <ry...@cruzio.com>.
Warren,
Can you supply the entire source for your JavaBean objects (TestCat.java
and TestItem.java)
-Richard
Warren wrote:
> I tried changing the int properties to Integer and I am still getting
> the same exceptions. I guess it is time to give up. Thanks for
> everyones help.
>
> Warren wrote:
>> I will give it a try. I don't seem to have this problem with other
>> sqlMaps I am using. This is the first n+1 I have tried. Is this the
>> Exception that leads you to believe that it is a primitive mapping
>> problem:
>>
>> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMappingValue(BasicResultMap.java:268)
>>
>>
>> Jeff Butler wrote:
>>> Thanks for the stack trace.
>>>
>>> I'll have to look into this a little further. iBATIS is a little
>>> finicky when it comes to using primitive types. You might have
>>> better luck if you changed to using Integer instead of int for the
>>> primary keys.
>>>
>>> Jeff Butler
>>>
>>>
>>> On 12/1/06, *Warren* <warren@clarksnutrition.com
>>> <ma...@clarksnutrition.com>> wrote:
>>>
>>> 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
>>> >
>>>
>
>
Re: n+1 Problem NullPointerException
Posted by Warren <wa...@clarksnutrition.com>.
I tried changing the int properties to Integer and I am still getting
the same exceptions. I guess it is time to give up. Thanks for everyones
help.
Warren wrote:
> I will give it a try. I don't seem to have this problem with other
> sqlMaps I am using. This is the first n+1 I have tried. Is this the
> Exception that leads you to believe that it is a primitive mapping
> problem:
>
> com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMappingValue(BasicResultMap.java:268)
>
>
> Jeff Butler wrote:
>> Thanks for the stack trace.
>>
>> I'll have to look into this a little further. iBATIS is a little
>> finicky when it comes to using primitive types. You might have
>> better luck if you changed to using Integer instead of int for the
>> primary keys.
>>
>> Jeff Butler
>>
>>
>> On 12/1/06, *Warren* <warren@clarksnutrition.com
>> <ma...@clarksnutrition.com>> wrote:
>>
>> 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
>> >
>>
Re: n+1 Problem NullPointerException
Posted by Warren <wa...@clarksnutrition.com>.
I will give it a try. I don't seem to have this problem with other
sqlMaps I am using. This is the first n+1 I have tried. Is this the
Exception that leads you to believe that it is a primitive mapping problem:
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.getPrimitiveResultMappingValue(BasicResultMap.java:268)
Jeff Butler wrote:
> Thanks for the stack trace.
>
> I'll have to look into this a little further. iBATIS is a little
> finicky when it comes to using primitive types. You might have better
> luck if you changed to using Integer instead of int for the primary keys.
>
> Jeff Butler
>
>
> On 12/1/06, *Warren* <warren@clarksnutrition.com
> <ma...@clarksnutrition.com>> wrote:
>
> 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
> >
>
Re: n+1 Problem NullPointerException
Posted by Jeff Butler <je...@gmail.com>.
Thanks for the stack trace.
I'll have to look into this a little further. iBATIS is a little finicky
when it comes to using primitive types. You might have better luck if you
changed to using Integer instead of int for the primary keys.
Jeff Butler
On 12/1/06, Warren <wa...@clarksnutrition.com> wrote:
>
> 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
> >
>
>
Re: n+1 Problem NullPointerException
Posted by Warren <wa...@clarksnutrition.com>.
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* <warren@clarksnutrition.com
> <ma...@clarksnutrition.com>> 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.
>
>
Re: n+1 Problem NullPointerException
Posted by "Eric T. Blue" <er...@gmail.com>.
Hi Warren,
I believe I replied to this topic yesterday (not sure if it was received).
I'm not certain if this is the issue, but you should make sure that you
properly initialize all of your list properties:
e.g.
private List items = new ArrayList();
On 12/1/06, Jeff Butler <je...@gmail.com> 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 <wa...@clarksnutrition.com> 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.
> >
>
>
Re: n+1 Problem NullPointerException
Posted by Jeff Butler <je...@gmail.com>.
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 <wa...@clarksnutrition.com> 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.
>
Re: n+1 Problem NullPointerException
Posted by Warren <wa...@clarksnutrition.com>.
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.
Re: n+1 Problem NullPointerException
Posted by Stefan Langer <ma...@googlemail.com>.
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