db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Monroe <mon...@dukece.com>
Subject RE: NullPointerException using two database pools
Date Tue, 18 Nov 2008 17:48:50 GMT
The problem is that the term "database" is overloaded in Torque.
It can be used to refer to two things.  First, it can refer to the
Torque database schema representation.  I.e., the Map classes that
are created from the XML that contains the database name.

Second, it can refer to the database connection pool defined
in the initialization properties.

The dbname property in the Criteria object refers to the first
definition of the database name.  It is used by the code to
determine needed relationships, etc. defined in the related
schema identified by this name.  So, you get the null pointer
exception because the schema for the database doesn't exist.

That said, the way to use the same Torque object set with two
different databases at the same time is to use the Peer
methods with the connection parameter.  You can get the DB
specific connection via the Torque.getConnection( dbName )
static method.  This refers to the connection pool definitions.

Note that this works fine for a large majority of the Torque code.
There may still be a few places that the code revert back to the
default DB name internally. I think this is mostly in the Helper
utility classes.

Another place to be aware of is that you will need to specify
either the connection DB name or supply a connection object to
the record object save methods.

> -----Original Message-----
> From: Adam Allgaier [mailto:allgaier2@yahoo.com]
> Sent: Monday, November 17, 2008 1:29 PM
> To: Apache Torque Users List
> Subject: NullPointerException using two database pools
>
> I'm trying to create two separate connection pools and trying to have a
> query run against the second connection pool.  I get a null pointer
> exception when I try to run the modified code.  It seems to pick up the
> datasource properly, but I cannot figure out what is creating the NPE.
> Thanks in advance for your help.
>
> Adam :-)
>
> The code:
> -------------------------------------------------
> //old code, default pool, works fine:
> Criteria criteria = new Criteria();
>
> //new code, new pool, fails with NullPointerException (see below for
> more)
> Criteria criteria = new Criteria("newpool");
>
> //new code, a datasource pool that doesn't exist in torque, fails with
> java.lang.NullPointerException:
> //There was no DataSourceFactory configuredfor the connection boguspool
> Criteria criteria = new Criteria("boguspool");
>
>
> Here's the Torque.properties:
> -------------------------------------------------
>
> application.root = .
> torque.database.type = mysql
> torque.database.default = originalpool
>
> # the default pool:
> torque.database.name = originalpool
> torque.database.originalpool.adapter=mysql
> torque.dsfactory.originalpool.connection.driver = com.mysql.jdbc.Driver
> torque.dsfactory.originalpool.connection.url =
> jdbc:mysql://127.0.0.1/mydb
> torque.dsfactory.originalpool.factory=
> org.apache.torque.dsfactory.SharedPoolDataSourceFactory
> ...
>
> # the new pool
> torque.database.newpool.adapter=mysql
> torque.dsfactory.newpool.connection.driver = com.mysql.jdbc.Driver
> torque.dsfactory.newpool.connection.url = jdbc:mysql://127.0.0.1/mydb
> torque.dsfactory.newpool.factory=
> org.apache.torque.dsfactory.SharedPoolDataSourceFactory
> ...
>
> Here's the detailed exception:
> -------------------------------------------------
> java.lang.NullPointerException
>
> javax.servlet.ServletException: org.apache.torque.TorqueException
>         at
> com.caucho.jsp.PageContextImpl.handlePageException(PageContextImpl.java:1
> 210)
>         at
> _jsp._searchresults3__jsp._jspService(_searchresults3__jsp.java:369)
>         at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
>         at com.caucho.jsp.Page.pageservice(Page.java:578)
>         at
> com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:
> 195)
>         at
> com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain
> .java:97)
>         at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.ja
> va:266)
>         at
> com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherI
> mpl.java:494)
>         at
> com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherI
> mpl.java:358)
>         at
> com.caucho.jsp.PageContextImpl.include(PageContextImpl.java:1008)
>         at _jsp._search__jsp._jspService(search.jsp:61)
>         at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
>         at com.caucho.jsp.Page.pageservice(Page.java:578)
>         at
> com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:
> 195)
>         at
> com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.jav
> a:187)
>         at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.ja
> va:266)
>         at
> com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:270)
>         at
> com.caucho.server.port.TcpConnection.run(TcpConnection.java:678)
>         at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:721)
>         at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:643)
>         at java.lang.Thread.run(Thread.java:619)
> Caused by: org.apache.torque.TorqueException
>         at
> org.apache.torque.util.BasePeer.throwTorqueException(BasePeer.java:236)
>         at org.apache.torque.util.BasePeer.doSelect(BasePeer.java:1374)
>         at
> com.rolera.kys.model.BaseItemWarehousePeer.doSelectJoinAccountWarehouse(B
> aseItemWarehousePeer.java:849)
>         at
> com.rolera.kys.model.ItemWarehouse.getSearchResults(ItemWarehouse.java:59
> 1)
>         at _jsp._searchresults3__jsp._jspService(searchresults3.jsp:38)
>         at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
>         at com.caucho.jsp.Page.pageservice(Page.java:578)
>         at
> com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:
> 195)
>         at
> com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain
> .java:97)
>         at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.ja
> va:266)
>         at
> com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherI
> mpl.java:494)
>         at
> com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherI
> mpl.java:358)
>         at
> com.caucho.jsp.PageContextImpl.include(PageContextImpl.java:1008)
>         at _jsp._search__jsp._jspService(search.jsp:61)
>         at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
>         at com.caucho.jsp.Page.pageservice(Page.java:578)
>         at
> com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:
> 195)
>         at
> com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.jav
> a:187)
>         at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.ja
> va:266)
>         at
> com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:270)
>         at
> com.caucho.server.port.TcpConnection.run(TcpConnection.java:678)
>         at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:721)
>         at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:643)
>         at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>         at
> org.apache.torque.util.BasePeer.createQuery(BasePeer.java:1267)
>         at
> org.apache.torque.util.BasePeer.createQueryString(BasePeer.java:984)
>         at org.apache.torque.util.BasePeer.doSelect(BasePeer.java:1391)
>         at org.apache.torque.util.BasePeer.doSelect(BasePeer.java:1368)
>         at
> com.rolera.kys.model.BaseItemWarehousePeer.doSelectJoinAccountWarehouse(B
> aseItemWarehousePeer.java:849)
>         at
> com.rolera.kys.model.ItemWarehouse.getSearchResults(ItemWarehouse.java:59
> 1)
>         at _jsp._searchresults3__jsp._jspService(searchresults3.jsp:38)
>         at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
>         at com.caucho.jsp.Page.pageservice(Page.java:578)
>         at
> com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:
> 195)
>         at
> com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain
> .java:97)
>         at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.ja
> va:266)
>         at
> com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherI
> mpl.java:494)
>         at
> com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherI
> mpl.java:358)
>         at
> com.caucho.jsp.PageContextImpl.include(PageContextImpl.java:1008)
>         at _jsp._search__jsp._jspService(search.jsp:61)
>         at com.caucho.jsp.JavaPage.service(JavaPage.java:61)
>         at com.caucho.jsp.Page.pageservice(Page.java:578)
>         at
> com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:
> 195)
>         at
> com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.jav
> a:187)
>         at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.ja
> va:266)
>         at
> com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:270)
>         at
> com.caucho.server.port.TcpConnection.run(TcpConnection.java:678)
>         at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:721)
>         at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:643)
>
> at java.lang.Thread.run(Thread.java:619)
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>

DukeCE Privacy Statement:
Please be advised that this e-mail and any files transmitted with
it are confidential communication or may otherwise be privileged or
confidential and are intended solely for the individual or entity
to whom they are addressed. If you are not the intended recipient
you may not rely on the contents of this email or any attachments,
and we ask that you please not read, copy or retransmit this
communication, but reply to the sender and destroy the email, its
contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is
strictly prohibited.

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message