From torque-user-return-8026-apmail-db-torque-user-archive=db.apache.org@db.apache.org Tue Nov 18 17:51:04 2008 Return-Path: Delivered-To: apmail-db-torque-user-archive@www.apache.org Received: (qmail 26003 invoked from network); 18 Nov 2008 17:51:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Nov 2008 17:51:03 -0000 Received: (qmail 64992 invoked by uid 500); 18 Nov 2008 17:51:11 -0000 Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 64843 invoked by uid 500); 18 Nov 2008 17:51:11 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 64832 invoked by uid 99); 18 Nov 2008 17:51:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2008 09:51:11 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of monroe@dukece.com designates 152.3.166.24 as permitted sender) Received: from [152.3.166.24] (HELO dukece.com) (152.3.166.24) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2008 17:49:48 +0000 Received: from ([10.123.20.204]) by smtpgw1.dukece.com with ESMTP id 4440076.5591184; Tue, 18 Nov 2008 12:48:51 -0500 Received: from durham-e2k7ca1.dukece.com ([10.123.20.180]) by dukece-mail3.dukece.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 18 Nov 2008 12:48:51 -0500 Received: from durham-e2k7mb1.dukece.com ([10.123.20.181]) by durham-e2k7ca1.dukece.com ([10.123.20.180]) with mapi; Tue, 18 Nov 2008 12:48:51 -0500 From: Greg Monroe To: 'Apache Torque Users List' Date: Tue, 18 Nov 2008 12:48:50 -0500 Subject: RE: NullPointerException using two database pools Thread-Topic: NullPointerException using two database pools Thread-Index: AclI4m0Aty91qLuMQ8Sn1C4SrVM61wAv7Y3Q Message-ID: <55B8568AFA5F144F886F18186BAD5B2C25C66B9E@durham-e2k7mb1.dukece.com> References: <273807.78676.qm@web54604.mail.re2.yahoo.com> In-Reply-To: <273807.78676.qm@web54604.mail.re2.yahoo.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 18 Nov 2008 17:48:51.0699 (UTC) FILETIME=[EAF2EC30:01C949A5] Content-Type: text/plain; charset="us-ascii" X-Virus-Checked: Checked by ClamAV on apache.org The problem is that the term "database" is overloaded in Torque=2E=0D=0AIt = can be used to refer to two things=2E First, it can refer to the=0D=0ATorq= ue database schema representation=2E I=2Ee=2E, the Map classes that=0D=0Aa= re created from the XML that contains the database name=2E=0D=0A=0D=0ASecon= d, it can refer to the database connection pool defined=0D=0Ain the initial= ization properties=2E=0D=0A=0D=0AThe dbname property in the Criteria object= refers to the first=0D=0Adefinition of the database name=2E It is used by= the code to=0D=0Adetermine needed relationships, etc=2E defined in the rel= ated=0D=0Aschema identified by this name=2E So, you get the null pointer= =0D=0Aexception because the schema for the database doesn't exist=2E=0D=0A= =0D=0AThat said, the way to use the same Torque object set with two=0D=0Adi= fferent databases at the same time is to use the Peer=0D=0Amethods with the= connection parameter=2E You can get the DB=0D=0Aspecific connection via t= he Torque=2EgetConnection( dbName )=0D=0Astatic method=2E This refers to t= he connection pool definitions=2E=0D=0A=0D=0ANote that this works fine for = a large majority of the Torque code=2E=0D=0AThere may still be a few places= that the code revert back to the=0D=0Adefault DB name internally=2E I thin= k this is mostly in the Helper=0D=0Autility classes=2E=0D=0A=0D=0AAnother p= lace to be aware of is that you will need to specify=0D=0Aeither the connec= tion DB name or supply a connection object to=0D=0Athe record object save m= ethods=2E=0D=0A=0D=0A> -----Original Message-----=0D=0A> From: Adam Allgaie= r [mailto:allgaier2@yahoo=2Ecom]=0D=0A> Sent: Monday, November 17, 2008 1:2= 9 PM=0D=0A> To: Apache Torque Users List=0D=0A> Subject: NullPointerExcepti= on using two database pools=0D=0A>=0D=0A> I'm trying to create two separate= connection pools and trying to have a=0D=0A> query run against the second = connection pool=2E I get a null pointer=0D=0A> exception when I try to run= the modified code=2E It seems to pick up the=0D=0A> datasource properly, = but I cannot figure out what is creating the NPE=2E=0D=0A> Thanks in advanc= e for your help=2E=0D=0A>=0D=0A> Adam :-)=0D=0A>=0D=0A> The code:=0D=0A> --= -----------------------------------------------=0D=0A> //old code, default = pool, works fine:=0D=0A> Criteria criteria =3D new Criteria();=0D=0A>=0D=0A= > //new code, new pool, fails with NullPointerException (see below for=0D= =0A> more)=0D=0A> Criteria criteria =3D new Criteria("newpool");=0D=0A>=0D= =0A> //new code, a datasource pool that doesn't exist in torque, fails with= =0D=0A> java=2Elang=2ENullPointerException:=0D=0A> //There was no DataSourc= eFactory configuredfor the connection boguspool=0D=0A> Criteria criteria = =3D new Criteria("boguspool");=0D=0A>=0D=0A>=0D=0A> Here's the Torque=2Epro= perties:=0D=0A> -------------------------------------------------=0D=0A>=0D= =0A> application=2Eroot =3D =2E=0D=0A> torque=2Edatabase=2Etype =3D mysql= =0D=0A> torque=2Edatabase=2Edefault =3D originalpool=0D=0A>=0D=0A> # the de= fault pool:=0D=0A> torque=2Edatabase=2Ename =3D originalpool=0D=0A> torque= =2Edatabase=2Eoriginalpool=2Eadapter=3Dmysql=0D=0A> torque=2Edsfactory=2Eor= iginalpool=2Econnection=2Edriver =3D com=2Emysql=2Ejdbc=2EDriver=0D=0A> tor= que=2Edsfactory=2Eoriginalpool=2Econnection=2Eurl =3D=0D=0A> jdbc:mysql://1= 27=2E0=2E0=2E1/mydb=0D=0A> torque=2Edsfactory=2Eoriginalpool=2Efactory=3D= =0D=0A> org=2Eapache=2Etorque=2Edsfactory=2ESharedPoolDataSourceFactory=0D= =0A> =2E=2E=2E=0D=0A>=0D=0A> # the new pool=0D=0A> torque=2Edatabase=2Enewp= ool=2Eadapter=3Dmysql=0D=0A> torque=2Edsfactory=2Enewpool=2Econnection=2Edr= iver =3D com=2Emysql=2Ejdbc=2EDriver=0D=0A> torque=2Edsfactory=2Enewpool=2E= connection=2Eurl =3D jdbc:mysql://127=2E0=2E0=2E1/mydb=0D=0A> torque=2Edsfa= ctory=2Enewpool=2Efactory=3D=0D=0A> org=2Eapache=2Etorque=2Edsfactory=2ESha= redPoolDataSourceFactory=0D=0A> =2E=2E=2E=0D=0A>=0D=0A> Here's the detailed= exception:=0D=0A> -------------------------------------------------=0D=0A>= java=2Elang=2ENullPointerException=0D=0A>=0D=0A> javax=2Eservlet=2EServlet= Exception: org=2Eapache=2Etorque=2ETorqueException=0D=0A> at=0D=0A>= com=2Ecaucho=2Ejsp=2EPageContextImpl=2EhandlePageException(PageContextImpl= =2Ejava:1=0D=0A> 210)=0D=0A> at=0D=0A> _jsp=2E_searchresults3__jsp= =2E_jspService(_searchresults3__jsp=2Ejava:369)=0D=0A> at com=2Ecau= cho=2Ejsp=2EJavaPage=2Eservice(JavaPage=2Ejava:61)=0D=0A> at com=2E= caucho=2Ejsp=2EPage=2Epageservice(Page=2Ejava:578)=0D=0A> at=0D=0A>= com=2Ecaucho=2Eserver=2Edispatch=2EPageFilterChain=2EdoFilter(PageFilterCh= ain=2Ejava:=0D=0A> 195)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Ewe= bapp=2EDispatchFilterChain=2EdoFilter(DispatchFilterChain=0D=0A> =2Ejava:97= )=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Edispatch=2EServletInvoca= tion=2Eservice(ServletInvocation=2Eja=0D=0A> va:266)=0D=0A> at=0D= =0A> com=2Ecaucho=2Eserver=2Ewebapp=2ERequestDispatcherImpl=2Einclude(Reque= stDispatcherI=0D=0A> mpl=2Ejava:494)=0D=0A> at=0D=0A> com=2Ecaucho= =2Eserver=2Ewebapp=2ERequestDispatcherImpl=2Einclude(RequestDispatcherI=0D= =0A> mpl=2Ejava:358)=0D=0A> at=0D=0A> com=2Ecaucho=2Ejsp=2EPageCont= extImpl=2Einclude(PageContextImpl=2Ejava:1008)=0D=0A> at _jsp=2E_se= arch__jsp=2E_jspService(search=2Ejsp:61)=0D=0A> at com=2Ecaucho=2Ej= sp=2EJavaPage=2Eservice(JavaPage=2Ejava:61)=0D=0A> at com=2Ecaucho= =2Ejsp=2EPage=2Epageservice(Page=2Ejava:578)=0D=0A> at=0D=0A> com= =2Ecaucho=2Eserver=2Edispatch=2EPageFilterChain=2EdoFilter(PageFilterChain= =2Ejava:=0D=0A> 195)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Ewebap= p=2EWebAppFilterChain=2EdoFilter(WebAppFilterChain=2Ejav=0D=0A> a:187)=0D= =0A> at=0D=0A> com=2Ecaucho=2Eserver=2Edispatch=2EServletInvocation= =2Eservice(ServletInvocation=2Eja=0D=0A> va:266)=0D=0A> at=0D=0A> c= om=2Ecaucho=2Eserver=2Ehttp=2EHttpRequest=2EhandleRequest(HttpRequest=2Ejav= a:270)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Eport=2ETcpConnectio= n=2Erun(TcpConnection=2Ejava:678)=0D=0A> at com=2Ecaucho=2Eutil=2ET= hreadPool$Item=2ErunTasks(ThreadPool=2Ejava:721)=0D=0A> at com=2Eca= ucho=2Eutil=2EThreadPool$Item=2Erun(ThreadPool=2Ejava:643)=0D=0A> a= t java=2Elang=2EThread=2Erun(Thread=2Ejava:619)=0D=0A> Caused by: org=2Eapa= che=2Etorque=2ETorqueException=0D=0A> at=0D=0A> org=2Eapache=2Etorq= ue=2Eutil=2EBasePeer=2EthrowTorqueException(BasePeer=2Ejava:236)=0D=0A> = at org=2Eapache=2Etorque=2Eutil=2EBasePeer=2EdoSelect(BasePeer=2Ejava:= 1374)=0D=0A> at=0D=0A> com=2Erolera=2Ekys=2Emodel=2EBaseItemWarehou= sePeer=2EdoSelectJoinAccountWarehouse(B=0D=0A> aseItemWarehousePeer=2Ejava:= 849)=0D=0A> at=0D=0A> com=2Erolera=2Ekys=2Emodel=2EItemWarehouse=2E= getSearchResults(ItemWarehouse=2Ejava:59=0D=0A> 1)=0D=0A> at _jsp= =2E_searchresults3__jsp=2E_jspService(searchresults3=2Ejsp:38)=0D=0A> = at com=2Ecaucho=2Ejsp=2EJavaPage=2Eservice(JavaPage=2Ejava:61)=0D=0A> = at com=2Ecaucho=2Ejsp=2EPage=2Epageservice(Page=2Ejava:578)=0D=0A> = at=0D=0A> com=2Ecaucho=2Eserver=2Edispatch=2EPageFilterChain=2EdoFilt= er(PageFilterChain=2Ejava:=0D=0A> 195)=0D=0A> at=0D=0A> com=2Ecauch= o=2Eserver=2Ewebapp=2EDispatchFilterChain=2EdoFilter(DispatchFilterChain=0D= =0A> =2Ejava:97)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Edispatch= =2EServletInvocation=2Eservice(ServletInvocation=2Eja=0D=0A> va:266)=0D=0A>= at=0D=0A> com=2Ecaucho=2Eserver=2Ewebapp=2ERequestDispatcherImpl= =2Einclude(RequestDispatcherI=0D=0A> mpl=2Ejava:494)=0D=0A> at=0D= =0A> com=2Ecaucho=2Eserver=2Ewebapp=2ERequestDispatcherImpl=2Einclude(Reque= stDispatcherI=0D=0A> mpl=2Ejava:358)=0D=0A> at=0D=0A> com=2Ecaucho= =2Ejsp=2EPageContextImpl=2Einclude(PageContextImpl=2Ejava:1008)=0D=0A> = at _jsp=2E_search__jsp=2E_jspService(search=2Ejsp:61)=0D=0A> at= com=2Ecaucho=2Ejsp=2EJavaPage=2Eservice(JavaPage=2Ejava:61)=0D=0A> = at com=2Ecaucho=2Ejsp=2EPage=2Epageservice(Page=2Ejava:578)=0D=0A> = at=0D=0A> com=2Ecaucho=2Eserver=2Edispatch=2EPageFilterChain=2EdoFilter(Pa= geFilterChain=2Ejava:=0D=0A> 195)=0D=0A> at=0D=0A> com=2Ecaucho=2Es= erver=2Ewebapp=2EWebAppFilterChain=2EdoFilter(WebAppFilterChain=2Ejav=0D=0A= > a:187)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Edispatch=2EServle= tInvocation=2Eservice(ServletInvocation=2Eja=0D=0A> va:266)=0D=0A> = at=0D=0A> com=2Ecaucho=2Eserver=2Ehttp=2EHttpRequest=2EhandleRequest(HttpRe= quest=2Ejava:270)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Eport=2ET= cpConnection=2Erun(TcpConnection=2Ejava:678)=0D=0A> at com=2Ecaucho= =2Eutil=2EThreadPool$Item=2ErunTasks(ThreadPool=2Ejava:721)=0D=0A> = at com=2Ecaucho=2Eutil=2EThreadPool$Item=2Erun(ThreadPool=2Ejava:643)=0D=0A= > at java=2Elang=2EThread=2Erun(Thread=2Ejava:619)=0D=0A> Caused by= : java=2Elang=2ENullPointerException=0D=0A> at=0D=0A> org=2Eapache= =2Etorque=2Eutil=2EBasePeer=2EcreateQuery(BasePeer=2Ejava:1267)=0D=0A> = at=0D=0A> org=2Eapache=2Etorque=2Eutil=2EBasePeer=2EcreateQueryString(B= asePeer=2Ejava:984)=0D=0A> at org=2Eapache=2Etorque=2Eutil=2EBasePe= er=2EdoSelect(BasePeer=2Ejava:1391)=0D=0A> at org=2Eapache=2Etorque= =2Eutil=2EBasePeer=2EdoSelect(BasePeer=2Ejava:1368)=0D=0A> at=0D=0A= > com=2Erolera=2Ekys=2Emodel=2EBaseItemWarehousePeer=2EdoSelectJoinAccountW= arehouse(B=0D=0A> aseItemWarehousePeer=2Ejava:849)=0D=0A> at=0D=0A>= com=2Erolera=2Ekys=2Emodel=2EItemWarehouse=2EgetSearchResults(ItemWarehous= e=2Ejava:59=0D=0A> 1)=0D=0A> at _jsp=2E_searchresults3__jsp=2E_jspS= ervice(searchresults3=2Ejsp:38)=0D=0A> at com=2Ecaucho=2Ejsp=2EJava= Page=2Eservice(JavaPage=2Ejava:61)=0D=0A> at com=2Ecaucho=2Ejsp=2EP= age=2Epageservice(Page=2Ejava:578)=0D=0A> at=0D=0A> com=2Ecaucho=2E= server=2Edispatch=2EPageFilterChain=2EdoFilter(PageFilterChain=2Ejava:=0D= =0A> 195)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Ewebapp=2EDispatc= hFilterChain=2EdoFilter(DispatchFilterChain=0D=0A> =2Ejava:97)=0D=0A> = at=0D=0A> com=2Ecaucho=2Eserver=2Edispatch=2EServletInvocation=2Eservice= (ServletInvocation=2Eja=0D=0A> va:266)=0D=0A> at=0D=0A> com=2Ecauch= o=2Eserver=2Ewebapp=2ERequestDispatcherImpl=2Einclude(RequestDispatcherI=0D= =0A> mpl=2Ejava:494)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Ewebap= p=2ERequestDispatcherImpl=2Einclude(RequestDispatcherI=0D=0A> mpl=2Ejava:35= 8)=0D=0A> at=0D=0A> com=2Ecaucho=2Ejsp=2EPageContextImpl=2Einclude(= PageContextImpl=2Ejava:1008)=0D=0A> at _jsp=2E_search__jsp=2E_jspSe= rvice(search=2Ejsp:61)=0D=0A> at com=2Ecaucho=2Ejsp=2EJavaPage=2Ese= rvice(JavaPage=2Ejava:61)=0D=0A> at com=2Ecaucho=2Ejsp=2EPage=2Epag= eservice(Page=2Ejava:578)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2E= dispatch=2EPageFilterChain=2EdoFilter(PageFilterChain=2Ejava:=0D=0A> 195)= =0D=0A> at=0D=0A> com=2Ecaucho=2Eserver=2Ewebapp=2EWebAppFilterChai= n=2EdoFilter(WebAppFilterChain=2Ejav=0D=0A> a:187)=0D=0A> at=0D=0A>= com=2Ecaucho=2Eserver=2Edispatch=2EServletInvocation=2Eservice(ServletInvo= cation=2Eja=0D=0A> va:266)=0D=0A> at=0D=0A> com=2Ecaucho=2Eserver= =2Ehttp=2EHttpRequest=2EhandleRequest(HttpRequest=2Ejava:270)=0D=0A> = at=0D=0A> com=2Ecaucho=2Eserver=2Eport=2ETcpConnection=2Erun(TcpConnectio= n=2Ejava:678)=0D=0A> at com=2Ecaucho=2Eutil=2EThreadPool$Item=2Erun= Tasks(ThreadPool=2Ejava:721)=0D=0A> at com=2Ecaucho=2Eutil=2EThread= Pool$Item=2Erun(ThreadPool=2Ejava:643)=0D=0A>=0D=0A> at java=2Elang=2EThrea= d=2Erun(Thread=2Ejava:619)=0D=0A>=0D=0A>=0D=0A>=0D=0A>=0D=0A>=0D=0A> ------= ---------------------------------------------------------------=0D=0A> To u= nsubscribe, e-mail: torque-user-unsubscribe@db=2Eapache=2Eorg=0D=0A> For ad= ditional commands, e-mail: torque-user-help@db=2Eapache=2Eorg=0D=0A>=0D=0A= =0D=0ADukeCE Privacy Statement:=0D=0APlease be advised that this e-mail and= any files transmitted with=0Ait are confidential communication or may othe= rwise be privileged or=0Aconfidential and are intended solely for the indiv= idual or entity=0Ato whom they are addressed=2E If you are not the intended= recipient=0Ayou may not rely on the contents of this email or any attachme= nts,=0Aand we ask that you please not read, copy or retransmit this=0Acommu= nication, but reply to the sender and destroy the email, its=0Acontents, an= d all copies thereof immediately=2E Any unauthorized=0Adissemination, distr= ibution or copying of this communication is=0Astrictly prohibited=2E --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org