OK. You asked for it.

I will try to make this as clean and readable as possible:

1) jboss.jcml entries
2) connection creation
3) static methods for closing Connections/Statements and Results Sets
4) Stack Trace of rmi Error when calling the static methods
5) Stack Trace of NullPointerException on closing of PreparedStatement

1) *** JBOSS.JCML:

   <mbean code="org.jboss.jdbc.JdbcProvider"
name="DefaultDomain:service=JdbcProvider">
     <attribute name="Drivers">oracle.jdbc.driver.OracleDriver</attribute>
   </mbean>

  <mbean code="org.jboss.jdbc.XADataSourceLoader"
name="DefaultDomain:service=XADataSource,name=OracleDS">
    <attribute name="PoolName">OracleDS</attribute>
    <attribute
name="DataSourceClass">org.opentools.minerva.jdbc.xa.wrapper.XADataSourceImp
l</attribute>
    <attribute
name="URL">jdbc:oracle:thin:@superman:1521:beedev2</attribute>
    <attribute name="JDBCUser">RV10</attribute>
    <attribute name="Password">RV10</attribute>
    <attribute name="InvalidateOnError">false</attribute>
    <attribute name="TimestampUsed">false</attribute>
    <attribute name="Blocking">true</attribute>
 <attribute name="GCEnabled">false</attribute>
    <attribute name="GCInterval">120000</attribute>
    <attribute name="GCMinIdleTime">1200000</attribute>
    <attribute name="IdleTimeout">120000</attribute>
    <attribute name="IdleTimeoutEnabled">true</attribute>
    <attribute name="LoggingEnabled">true</attribute>
    <attribute name="MaxIdleTimeoutPercent">1</attribute>
    <attribute name="MaxSize">10</attribute>
    <attribute name="MinSize">0</attribute>
 <attribute name="Properties"></attribute>
  </mbean>

2) *** CONNECTION CREATION
   InitialContext jndiContext = new InitialContext();
   XAPoolDataSource ds = (XAPoolDataSource)
jndiContext.lookup("java:/OracleDS");
   Connection conn = ds.getConnection();

3) *** static methods for closing rs/conn/stmt  ( I will place the entire
class here -- sorry if the readability is a little bad, tried to crunch it
all in )
import java.sql.*;
public class DatabaseUtility {

    public DatabaseUtility() { }
    public static void closeConnection(Connection connection) {
        try {
                if(connection == null)
                    return;
                try {
                    connection.close();
                }catch(Exception exception) {
                    try {
                        if( !connection.isClosed() ); // no need to throw
                    }catch(Exception exception1) {  }
                }
        }catch(Exception exception) { /* catches everything */ }
    }// end closeConnection

    public static void closeStatement(Statement statement) {
        try {
            if(statement == null)
                return;
            try {
                statement.close();
            }catch(Exception exception) { }
        }catch(Exception exception) { }
    } // end closeStatement

    public static void closeResultSet(ResultSet resultset) {
        try {
            if(resultset == null)
                return;
            try {
                resultset.close();
            }catch(Exception exception) { }
        }catch(Exception exception) { }
    } // end closeResultSet
}// end class

4) *** RMI ServerException Stack Trace ( this is thrown and the connection
is NOT returned to the pool )
    This is thrown when I try to call DatabaseUtility.closeConnection(
connection ); (notice I catch _everything_ in that method) and is _not_
thrown in the DatabaseUtility, but seems like it is thrown on the attempt to
call the method.
java.rmi.ServerException: Transaction rolled
back:com/bebee/recommender/utility/DatabaseUtility
        at org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:300)
        at
org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSe
ssionInstanceInterceptor.java:87)
        at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:19
0)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
        at
org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.jav
a:271)
        at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerI
nvoker.java:482)
        at
org.jboss.ejb.plugins.jrmp.interfaces.StatelessSessionProxy.invoke(Stateless
SessionProxy.java:152)
        at $Proxy5.exportUserAttributeValueRating(Unknown Source)
        at
com.bebee.recommender.client.web.servlet.XAServlet.executeAVRExport(XAServle
t.java:263) // call to the bean
        at
com.bebee.recommender.client.web.servlet.XAServlet.executeAVRXA(XAServlet.ja
va:163)     // call to method to call bean
        at
com.bebee.recommender.client.web.servlet.XAServlet.doPost(XAServlet.java:91)
// duh.
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
        at org.apache.tomcat.core.Handler.service(Handler.java:286)
        at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
        at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
        at java.lang.Thread.run(Thread.java:484)

5) *** NullPointerException stack trace (sorry for the log format) this is
thrown on the preparedStatement.close() call inside the bean at the end of
the transaction (which is directly after the call to connection.close() --
when I change the order of the calls, i.e. first close the prepared
statement then close the connection it works fine)

[AVR] java.lang.NullPointerException
[AVR]   at
org.opentools.minerva.jdbc.PreparedStatementInPool.close(PreparedStatementIn
Pool.java:421)
[AVR]   at
com.bebee.recommender.client.ejb.bean.xaction.AVRBean.exportUserAttributeVal
ueRating(AVRBean.java:197)
[AVR]   at java.lang.reflect.Method.invoke(Native Method)
[AVR]   at
org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(Stateles
sSessionContainer.java:472)
[AVR]   at
org.jboss.ejb.plugins.TxInterceptorBMT.invoke(TxInterceptorBMT.java:261)
[AVR]   at
org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSe
ssionInstanceInterceptor.java:87)
[AVR]   at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:19
0)
[AVR]   at
org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
[AVR]   at
org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.jav
a:271)
[AVR]   at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerI
nvoker.java:482)
[AVR]   at
org.jboss.ejb.plugins.jrmp.interfaces.StatelessSessionProxy.invoke(Stateless
SessionProxy.java:152)
[AVR]   at $Proxy5.exportUserAttributeValueRating(Unknown Source)
[AVR]   at
com.bebee.recommender.client.web.servlet.XAServlet.executeAVRExport(XAServle
t.java:263)         // my servlet
[AVR]   at
com.bebee.recommender.client.web.servlet.XAServlet.executeAVRXA(XAServlet.ja
va:163)
[AVR]   at
com.bebee.recommender.client.web.servlet.XAServlet.doPost(XAServlet.java:91)
[AVR]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
[AVR]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[AVR]   at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
[AVR]   at org.apache.tomcat.core.Handler.service(Handler.java:286)
[AVR]   at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
[AVR]   at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
[AVR]   at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
[AVR]   at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
[AVR]   at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
[AVR]   at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
[AVR]   at java.lang.Thread.run(Thread.java:484)


Hope all that helps and thanks for the help
scott

----- Original Message -----
From: "Toby Allsopp" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 15, 2001 1:40 PM
Subject: Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)


> On Tue, May 15, 2001 at 01:23:13PM -0700, <enter name here> wrote:
> > Toby -
> >
> > Well, I have a class with static utility methods such as:
> >
> >     public static void closeConnection(Connection connection)
> >     public static void closeStatement(Statement statement)
> >     public static void closeResultSet(ResultSet resultset)
> >
> > which, back in the day had a little more utility for getting pooled
> > connections for non-bean stuff - I just kept the close calls because it
> > keeps me from having try/catch blocks in my finally blocks...
> >
> > anyway, my beans use JNDI to get the pooled connections now and I was
> > continuing to use these static calls, but received rmi errors ( a la
> > java.rmi.ServerException: Transaction
> > rolledback:com/bebee/recommender/utility/DatabaseUtility ).
>
> Please, provide details here. *Exactly* where did you receive this
exception?
> What was the stacktrace?  What code is in those static methods?
>
> > So I removed the calls to these static methods and replaced them with
> > Connection.close(), etc calls. This stopped the rmi errors. My
conclusion
> > here was that an ejb calling static methods is apparently a bad thing
(makes
> > sense since it is trying to circumvent the container, i guess?)
>
> There is no problem with calling static methods in utility classes from
> an EJB.
>
> > The next problem was that since I was used to using my utility methods
> > (which checked for nulls being passed in) I grew lazy and closed things
in
> > no particular order which resulted in NullPointerExceptions when I did
the
> > following:
> >
> >         conn.close();
> >         preparedstmt.close(); // null pointer here
> >         // interesting point to make here -- no errors on regular
statements
> > closed here, just prepared ones... seemes rather odd ( i would be
interested
> > to hear more about this)
> >         rs.close();
>
> Ah, yes, this will give you problems because the statements and result
sets
> need to have references to the connection on which they were created.  You
> shouldn't get an exception, though, it should just be ignored.
>
> If you post the stacktraces then we can look into what's causing the NPE.
>
> > According to colleagues the 'proper' order for closing this stuff is
> > ResultSet then Statement then Connection - so I will take them at their
> > word.
>
> Yes, it makes a lot more sense to close them in that order, but the pooled
> connections shouldn't be so fragile.
>
> > So in conclusion, I confiused the hell out of myself -- which is good
every
> > now and again.
>
> Well, only if you get some understanding to replace the confusion.
>
> Toby.
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to