Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 57480 invoked from network); 2 Dec 2006 00:47:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Dec 2006 00:47:05 -0000 Received: (qmail 62850 invoked by uid 500); 2 Dec 2006 00:47:12 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 62838 invoked by uid 500); 2 Dec 2006 00:47:12 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 62827 invoked by uid 99); 2 Dec 2006 00:47:12 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Dec 2006 16:47:12 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [66.160.183.118] (HELO unassigned118.fc.aoindustries.com) (66.160.183.118) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Dec 2006 16:46:59 -0800 Received: from [192.168.1.27] (69-178-166-18-static-ip.telepacific.net [69.178.166.18] (may be forged)) (authenticated bits=0) by mongo.clarksnutrition.com (8.13.1/8.13.1) with ESMTP id kB20kcOP013751 for ; Fri, 1 Dec 2006 16:46:38 -0800 Message-ID: <4570CF5D.7000305@clarksnutrition.com> Date: Fri, 01 Dec 2006 16:57:01 -0800 From: Warren User-Agent: Thunderbird 1.5.0.8 (Windows/20061025) MIME-Version: 1.0 To: user-java@ibatis.apache.org Subject: Re: n+1 Problem NullPointerException References: <456FA23C.20304@clarksnutrition.com> <456FEE6B.3020506@googlemail.com> <4570BEBE.2010804@clarksnutrition.com> <4570CCBB.6090405@clarksnutrition.com> In-Reply-To: <4570CCBB.6090405@clarksnutrition.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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* > > 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) >> >> >> >> >> >> > >> jdbcType="INTEGER"/> >> >> > >> jdbcType="CHAR"/> >> >> > >> resultMap="CatItem.itemsResults" /> >> >> >> >> >> >> > >> jdbcType="CHAR"/> >> >> >> >> >> >> >> >> >> >> 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: >> >> >> > jdbcType="NUMERIC" nullValue="0"/> >> > jdbcType="CHAR" nullValue="NULL"/> >> > resultMap="CatItem.itemsResults" /> >> >> >> >> > jdbcType="NUMERIC" nullValue="0"/> >> > jdbcType="CHAR" nullValue="NULL"/> >> >> >> >> >> 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. >> >>