Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 45666 invoked from network); 19 Apr 2006 02:30:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Apr 2006 02:30:54 -0000 Received: (qmail 91420 invoked by uid 500); 19 Apr 2006 02:30:52 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 91399 invoked by uid 500); 19 Apr 2006 02:30:51 -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 91388 invoked by uid 99); 19 Apr 2006 02:30:51 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Apr 2006 19:30:51 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of jeffgbutler@gmail.com designates 66.249.82.196 as permitted sender) Received: from [66.249.82.196] (HELO xproxy.gmail.com) (66.249.82.196) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Apr 2006 19:30:50 -0700 Received: by xproxy.gmail.com with SMTP id i31so768186wxd for ; Tue, 18 Apr 2006 19:30:29 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=Br+7KLHEXxAH1+e66VukndS5rGSHFg0gQFCY/ML0LQ6wrdXAGeqM32yHihYCdGKGuh4kIkNeBbhgrRd4FSGo9yoqkF8HUARyYXEMuk1WCC3SxM2XzeVK2Yetu02YQcc+lZH+gsVrSwDfc0RAQc68kG8iLI5MBcQUtOSQvxmXIa4= Received: by 10.70.29.13 with SMTP id c13mr3078122wxc; Tue, 18 Apr 2006 19:30:29 -0700 (PDT) Received: by 10.70.69.16 with HTTP; Tue, 18 Apr 2006 19:30:29 -0700 (PDT) Message-ID: Date: Tue, 18 Apr 2006 21:30:29 -0500 From: "Jeff Butler" To: user-java@ibatis.apache.org Subject: Re: N Plus 1 Mapping Always getting a null pointer In-Reply-To: <44457B90.4070608@cpsc.ucalgary.ca> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_15541_2704138.1145413829091" References: <44454F57.30501@cpsc.ucalgary.ca> <44455E57.2090809@cpsc.ucalgary.ca> <44456C6D.6050601@cpsc.ucalgary.ca> <44457B90.4070608@cpsc.ucalgary.ca> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N ------=_Part_15541_2704138.1145413829091 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hmmm...You can't cast a List to an array - so you must have meant something else - were you calling the toArray() method and saving the result as an array internally? In my testing I've observed that iBATIS will call the setVotes method once with null, once again with an empty ArrayList. Then it will repeatedly cal= l getVotes for all the remaining votes rows. Note that iBATIS does not compose the entire List and send it to the setVotes method at one time. Th= e initial list will be empty, then the getVotes method will be called repeatedly to add a Vote object one at a time. You best hope for success is to have a private List of votes, and simple getters and setters. Trying to do anything wierd in the setters and getter= s will cause unpredictable results - like you're seeing. If you are still having trouble after making simple getters and setters, then please send your BasicStakeholder class along with your reply. Jeff Butler On 4/18/06, Eric Bauld wrote: > > setVotes was casting to an array. But when I added a if(votes =3D=3D > null){return;} for testing or removed all code in the method. > and left it as > setVotes(List votes){} > > I would then get this ClassCastException(included below) if the setter > method for setVotes has code in it or not. > > > Its as if my resultMap for BasicVote is failing. As it would build the > stakeholder object when I removed the > > from the stakeMap resultMap. I cannot see a problem in my resultMap, I > have looked over it many times. > > I am already using the BasicVote object in vote.xml(included below) and > I can get votes from the DB just fine. > But its not working within stakeholder.xml > > --------------Exception trace Follows: > com.ibatis.common.jdbc.exception.NestedSQLException: > --- The error occurred in config/maps/stakeholder.xml. > --- The error occurred while applying a result map. > --- Check the Stakeholder.stakeMap. > --- The error happened while setting a property on the result object. > --- Cause: java.lang.ClassCastException > Caused by: java.lang.ClassCastException > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryW= ithCallback > (GeneralStatement.java:188) > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryF= orList > (GeneralStatement.java:123) > at > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList( > SqlMapExecutorDelegate.java:610) > at > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList( > SqlMapExecutorDelegate.java:584) > at > com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList( > SqlMapSessionImpl.java:101) > at > com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList( > SqlMapClientImpl.java:78) > at > rp.broker.StakeholderBroker.getStakeholders(StakeholderBroker.java:81) > at > test.rp.broker.TestStakeholderBroker.testGetStakeholders( > TestStakeholderBroker.java:37) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java > :39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke( > DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at junit.framework.TestCase.runTest(TestCase.java:154) > at junit.framework.TestCase.runBare(TestCase.java:127) > at junit.framework.TestResult$1.protect(TestResult.java:106) > at junit.framework.TestResult.runProtected(TestResult.java:124) > at junit.framework.TestResult.run(TestResult.java:109) > at junit.framework.TestCase.run(TestCase.java:118) > at junit.framework.TestSuite.runTest(TestSuite.java:208) > at junit.framework.TestSuite.run(TestSuite.java:203) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( > RemoteTestRunner.java:478) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run( > RemoteTestRunner.java:344) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( > RemoteTestRunner.java:196) > Caused by: java.lang.ClassCastException > at > > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMap= pingValue > (BasicResultMap.java:383) > at > > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResultM= ap > (BasicResultMap.java:369) > at > > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectVal= ues > (BasicResultMap.java:355) > at > > com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResul= tObject > (RowHandlerCallback.java:63) > at > com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults( > SqlExecutor.java:395) > at > com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery( > SqlExecutor.java:185) > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQue= ry > (GeneralStatement.java:205) > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryW= ithCallback > (GeneralStatement.java:173) > ... 22 more > > Caused by: > java.lang.ClassCastException > at > > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setNestedResultMap= pingValue > (BasicResultMap.java:383) > at > > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResultM= ap > (BasicResultMap.java:369) > at > > com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectVal= ues > (BasicResultMap.java:355) > at > > com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResul= tObject > (RowHandlerCallback.java:63) > at > com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults( > SqlExecutor.java:395) > at > com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery( > SqlExecutor.java:185) > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQue= ry > (GeneralStatement.java:205) > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryW= ithCallback > (GeneralStatement.java:173) > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryF= orList > (GeneralStatement.java:123) > at > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList( > SqlMapExecutorDelegate.java:610) > at > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList( > SqlMapExecutorDelegate.java:584) > at > com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList( > SqlMapSessionImpl.java:101) > at > com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList( > SqlMapClientImpl.java:78) > at > rp.broker.StakeholderBroker.getStakeholders(StakeholderBroker.java:81) > at > test.rp.broker.TestStakeholderBroker.testGetStakeholders( > TestStakeholderBroker.java:37) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java > :39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke( > DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at junit.framework.TestCase.runTest(TestCase.java:154) > at junit.framework.TestCase.runBare(TestCase.java:127) > at junit.framework.TestResult$1.protect(TestResult.java:106) > at junit.framework.TestResult.runProtected(TestResult.java:124) > at junit.framework.TestResult.run(TestResult.java:109) > at junit.framework.TestCase.run(TestCase.java:118) > at junit.framework.TestSuite.runTest(TestSuite.java:208) > at junit.framework.TestSuite.run(TestSuite.java:203) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests( > RemoteTestRunner.java:478) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run( > RemoteTestRunner.java:344) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( > RemoteTestRunner.java:196) > > > ---------Vote.xml----------- > > > PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" > "http://www.ibatis.com/dtd/sql-map-2.dtd"> > > > > > > > INSERT INTO vote > (user_id,instance_id,requirement_id,criteria_id,value) > VALUES > (#userId#,#instanceId#,#requirementId#,#criteriaId#,#voteValue#) > ON DUPLICATE KEY UPDATE value=3D#voteValue#; > > > > > ------=_Part_15541_2704138.1145413829091 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Hmmm...You can't cast a List to an array - so you must have meant= something else - were you calling the toArray() method and saving the resu= lt as an array internally?
 
In my testing I've observed that iBATIS will call the setVotes method = once with null, once again with an empty ArrayList.  Then it will repe= atedly call getVotes for all the remaining votes rows.  Note that iBAT= IS does not compose the entire List and send it to the setVotes method at o= ne time.  The initial list will be empty, then the getVotes method wil= l be called repeatedly to add a Vote object one at a time.
 
You best hope for success is to have a private List of votes, and simp= le getters and setters.  Trying to do anything wierd in the setters an= d getters will cause unpredictable results - like you're seeing.
 
If you are still having trouble after making simple getters and setter= s, then please send your BasicStakeholder class along with your reply.
 
Jeff Butler
 
 

 
On 4/18/06, = Eric Bauld <baulde@cpsc.u= calgary.ca> wrote:
setVotes was casting to an array= . But when I added a if(votes =3D=3D
null){return;} for testing or remov= ed all code in the method.
and left it as
setVotes(List votes){}

I would then get this C= lassCastException(included below) if the setter
method for setVotes has = code in it or not.


Its as if my resultMap for BasicVote is faili= ng. As it would build the
stakeholder object when I removed the
<result property=3D"vo= tes" resultMap=3D"Stakeholder.votes"/>
from the stakeM= ap resultMap. I cannot see a problem in my resultMap, I
have looked over= it many times.

I am already using the BasicVote object in vote.xml(included below)=   and
I can get votes from the DB just fine.
But its not wo= rking within stakeholder.xml

--------------Exception trace Follows:<= br>com.ibatis.common.jdbc.exception.NestedSQLException :
--- The error occurred in config/maps/stakeholder.xml.
--- The erro= r occurred while applying a result map.
--- Check the Stakeholder.stakeM= ap.
--- The error happened while setting a property on the result object= .
--- Cause: java.lang.ClassCastException
Caused by: java.lang.ClassCa= stException
   at
com.ibatis.sqlmap.engine.mapping.statemen= t.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
&= nbsp;  at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryFor= List(GeneralStatement.java:123)
   at
com.ibatis.sqlmap.eng= ine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:61= 0)
   at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.que= ryForList(SqlMapExecutorDelegate.java:584)
   at
com.ibatis= .sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:1= 01)
   at
com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImp= l.java:78)
   at
rp.broker.StakeholderBroker.getStakeholder= s(StakeholderBroker.java:81)
   at
test.rp.broker.TestStake= holderBroker.testGetStakeholders (TestStakeholderBroker.java:37)
   at sun.reflect.NativeMethod= AccessorImpl.invoke0(Native Method)
   at
sun.reflect.Nativ= eMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  = ; at
sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect= .Method.invoke(Method.java:324)
   at junit.framework.TestCase= .runTest(TestCase.java:154)
   at junit.framework.TestCase.run= Bare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)   at junit.framework.TestResult.runProtected(TestResult.java:1= 24)
   at junit.framework.TestResult.run(TestResult.java:109)<= br>   at junit.framework.TestCase.run (TestCase.java:118)
   at junit.framework.TestSuite.runTest(Te= stSuite.java:208)
   at junit.framework.TestSuite.run(TestSuit= e.java:203)
   at
org.eclipse.jdt.internal.junit.runner.Rem= oteTestRunner.runTests(RemoteTestRunner.java :478)
   at
org.eclipse.jdt.internal.junit.runner.RemoteTes= tRunner.run(RemoteTestRunner.java:344)
   at
org.eclipse.jd= t.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)Caused by: java.lang.ClassCastException
   at
com.ibatis.sqlmap.engine.mapping.result.BasicResultM= ap.setNestedResultMappingValue(BasicResultMap.java:383)
   at<= br>com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResult= Map(BasicResultMap.java :369)
   at
com.ibatis.sqlmap.engine.mapping.result.BasicRe= sultMap.setResultObjectValues(BasicResultMap.java:355)
   atcom.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResul= tObject(RowHandlerCallback.java :63)
   at
com.ibatis.sqlmap.engine.execution.SqlExecutor.h= andleResults(SqlExecutor.java:395)
   at
com.ibatis.sqlmap.= engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
 &n= bsp; at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlE= xecuteQuery (GeneralStatement.java:205)
   at
com.ibatis.sqlmap.engine.= mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatemen= t.java:173)
   ... 22 more

Caused by:
java.lang.Clas= sCastException
   at
com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.s= etNestedResultMappingValue(BasicResultMap.java:383)
   at
c= om.ibatis.sqlmap.engine.mapping.result.BasicResultMap.applyNestedResultMap(= BasicResultMap.java :369)
   at
com.ibatis.sqlmap.engine.mapping.result.BasicRe= sultMap.setResultObjectValues(BasicResultMap.java:355)
   atcom.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResul= tObject(RowHandlerCallback.java :63)
   at
com.ibatis.sqlmap.engine.execution.SqlExecutor.h= andleResults(SqlExecutor.java:395)
   at
com.ibatis.sqlmap.= engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:185)
 &n= bsp; at
com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlE= xecuteQuery (GeneralStatement.java:205)
   at
com.ibatis.sqlmap.engine.= mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatemen= t.java:173)
   at
com.ibatis.sqlmap.engine.mapping.statemen= t.GeneralStatement.executeQueryForList (GeneralStatement.java:123)
   at
com.ibatis.sqlmap.engine.= impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)   at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.q= ueryForList(SqlMapExecutorDelegate.java :584)
   at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl= .queryForList(SqlMapSessionImpl.java:101)
   at
com.ibatis.= sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:78)<= br>   at
rp.broker.StakeholderBroker.getStakeholders (StakeholderBroker.java:81)
   at
test.rp.broker.TestStakeh= olderBroker.testGetStakeholders(TestStakeholderBroker.java:37)
 &nb= sp; at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 = ;  at
sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
   at
sun.reflect.Delega= tingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
&nbs= p;  at java.lang.reflect.Method.invoke(Method.java:324)
  = ; at junit.framework.TestCase.runTest (TestCase.java:154)
   at junit.framework.TestCase.runBare(Tes= tCase.java:127)
   at junit.framework.TestResult$1.protect(Tes= tResult.java:106)
   at junit.framework.TestResult.runProtecte= d(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
&nbs= p;  at junit.framework.TestCase.run(TestCase.java:118)
  = at junit.framework.TestSuite.runTest(TestSuite.java:208)
   a= t junit.framework.TestSuite.run(TestSuite.java :203)
   at
org.eclipse.jdt.internal.junit.runner.RemoteTes= tRunner.runTests(RemoteTestRunner.java:478)
   at
org.eclip= se.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344= )
   at
org.eclipse.jdt.internal.junit.runner.RemoteTestRun= ner.main (RemoteTestRunner.java:196)


---------Vote.xml-----------
<= ?xml version=3D"1.0" encoding=3D"UTF-8" ?>

&l= t;!DOCTYPE sqlMap
PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN"<= br> "http://www.ibatis= .com/dtd/sql-map-2.dtd">

<sqlMap namespace=3D"Vo= te">

   <select id=3D"getVotes" resul= tClass=3D" rp.object.baseImpl.BasicVote">
     &nb= sp; SELECT user_id AS userId,
       =     instance_id AS instanceId,
    &n= bsp;      requirement_id AS requirementId,
&nbs= p;          criteria_id AS cri= teriaId,
           va= lue AS voteValue
       FROM vote
   &nb= sp;   WHERE user_id =3D #userId#
     = ;  AND instance_id =3D #instanceId#
   </select>
   <insert id=3D"insertVotes" parameterClass=3D= "rp.object.baseImpl.BasicVote">
       INSERT INTO vote
(user_id,insta= nce_id,requirement_id,criteria_id,value)
     &= nbsp; VALUES
(#userId#,#instanceId#,#requirementId#,#criteriaId#,#voteVa= lue#)
       ON DUPLICATE KEY UPDATE value= =3D#voteValue#;
   </insert>
</sqlMap>


------=_Part_15541_2704138.1145413829091--