Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
Toby - well, now that everyone at work is finished laughing at me... you are correct, the class 'mysteriously' disappeared from my build script. thanks for ALL of your help! scott Looking at the TxInterceptorBMT code, I suspect that you are getting a NoClassDefFoundError for the DatabaseUtility class. Do you have that class in your ejb-jar? Try catching Throwable around the call to DatabaseUtility and printing the stacktrace. 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
[JBoss-user] RE: Error 'closing' a pooled connection (addendum)
OK. So here is the answer *I* came up with: Rule 1: It is bad to use utility classes with static methods from your beans - I got rmi errors Rule 2: Close your DB stuff in this order: ResultSet then Statement the Connection Not sure about Rule 1, but Rule 2 works. ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
On Tue, May 15, 2001 at 12:19:14PM -0700, enter name here wrote: OK. So here is the answer *I* came up with: Rule 1: It is bad to use utility classes with static methods from your beans - I got rmi errors Please provide some details about this. As it stands it makes no sense. Rule 2: Close your DB stuff in this order: ResultSet then Statement the Connection Hmm, this shouldn't be neccessary. Can you procide some details, such as exactly what you were doing to cuase the problems, and exactly what the problems were? Toby. ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
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 ). 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?) No this should work. This is a pretty common practice. What was the rest of the trace? There may have been a prior exception that would tell us more. 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 Or some other exception, or nothing, depending on the driver. // 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) Hmmm. Statement caches? rs.close(); According to colleagues the 'proper' order for closing this stuff is ResultSet then Statement then Connection - so I will take them at their word. With some drivers it won't matter, but I'd do as you're doing. You might want to make your static helper (once we figure out what's going on with those) take all three (connection, statement, resultset) as parameters so it can do it in order. You'd still want other overrides, though. So in conclusion, I confiused the hell out of myself -- which is good every now and again. Indeed it is! -danch ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
On Tue, May 15, 2001 at 03:06:42PM -0700, enter name here wrote: 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: Looks fine. 2) *** CONNECTION CREATION InitialContext jndiContext = new InitialContext(); XAPoolDataSource ds = (XAPoolDataSource) jndiContext.lookup(java:/OracleDS); Connection conn = ds.getConnection(); Don't reference Minerva classes in your code. Just use javax.sql.DataSource. Also, you should use java:comp/env/ lookups, but that's not relevent here. 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 { Looks fine. 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) Ok, you're missing out some details. Are you calling an EJB from a servlet? You haven't mentioned anything about what this EJB is doing. What are you doing with transactions? Are you getting the connection in the servlet and trying to close it from the EJB or something? 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) This is a bug. I'll look at this kind of fragility at some point. Toby. ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
2) *** CONNECTION CREATION InitialContext jndiContext = new InitialContext(); XAPoolDataSource ds = (XAPoolDataSource) jndiContext.lookup(java:/OracleDS); Connection conn = ds.getConnection(); Don't reference Minerva classes in your code. Just use javax.sql.DataSource. If you don't reference to Minerva class, could you tell us what is the alternative to cast the objref in PortableRemoteObject.narrow( objref, ? ) method ? dovan Also, you should use java:comp/env/ lookups, but that's not relevent here. 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 { Looks fine. 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) Ok, you're missing out some details. Are you calling an EJB from a servlet? You haven't mentioned anything about what this EJB is doing. What are you doing with transactions? Are you getting the connection in the servlet and trying to close it from the EJB or something? 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) This is a bug. I'll look at this kind of fragility at some point. 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
Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
I think I had ClassCastExceptions back when I first started with these pools and datasource lookups and the first fix I found was to use the Minerva specific class, but I just changed my code to this and it works fine: public class UPRBean implements SessionBean { transient DataSource ds = null; public void aMethod() { InitialContext jndiContext = new InitialContext(); ds = (DataSource) jndiContext.lookup(java:/OracleDS); } } of course, as Toby said: Also, you should use java:comp/env/ lookups - Original Message - From: Dovan Nguyen [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, May 15, 2001 3:53 PM Subject: Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum) 2) *** CONNECTION CREATION InitialContext jndiContext = new InitialContext(); XAPoolDataSource ds = (XAPoolDataSource) jndiContext.lookup(java:/OracleDS); Connection conn = ds.getConnection(); Don't reference Minerva classes in your code. Just use javax.sql.DataSource. If you don't reference to Minerva class, could you tell us what is the alternative to cast the objref in PortableRemoteObject.narrow( objref, ? ) method ? dovan Also, you should use java:comp/env/ lookups, but that's not relevent here. 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 { Looks fine. 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) Ok, you're missing out some details. Are you calling an EJB from a servlet? You haven't mentioned anything about what this EJB is doing. What are you doing with transactions? Are you getting the connection in the servlet and trying to close it from the EJB or something? 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) This is a bug. I'll look at this kind of fragility at some point. 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 ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
On Tue, May 15, 2001 at 03:53:22PM -0700, Dovan Nguyen wrote: 2) *** CONNECTION CREATION InitialContext jndiContext = new InitialContext(); XAPoolDataSource ds = (XAPoolDataSource) jndiContext.lookup(java:/OracleDS); Connection conn = ds.getConnection(); Don't reference Minerva classes in your code. Just use javax.sql.DataSource. If you don't reference to Minerva class, could you tell us what is the alternative to cast the objref in PortableRemoteObject.narrow( objref, ? ) method ? Cast it to whatever you expect. If you're looking up a DataSource, use javax.sql.DataSource because that's the interface you want. Toby. ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
Don't reference Minerva classes in your code. Just use javax.sql.DataSource. Also, you should use java:comp/env/ lookups, but that's not relevent here. ok. good point. 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) Ok, you're missing out some details. Are you calling an EJB from a servlet? You haven't mentioned anything about what this EJB is doing. What are you doing with transactions? Are you getting the connection in the servlet and trying to close it from the EJB or something? A servlet calls the bean it only passes primitive types (int, float, etc) into the bean, the bean gets its own connections from the pool and closes everything itself - the servlet simply determines which bean to call and gets form parameters to pass into the bean, the results are returned from the bean and are formatted into HTML to display them. The results may be Map objects, or primitive types This is, in fact not a transactional bean. All it does is retrieves data from the database and shoves it into a Map to return. It is a session bean because some of the lookups are a little complex (do not map directly to a table) -- and some of them require multiple row lookups - which you cannot do with entity beans. my ejb-jar.xml reads as follows: basically straight from the interest example: ...cut out ... session ejb-nameAVR/ejb-name homecom.bebee.recommender.client.ejb.interfaces.AVRHome/home remotecom.bebee.recommender.client.ejb.interfaces.AVRInterface/remote ejb-classcom.bebee.recommender.client.ejb.bean.xaction.AVRBean/ejb-class session-typeStateless/session-type transaction-typeBean/transaction-type// my understanding is that this mean I will handle transactions, if any /session ... cut out ... 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) This is a bug. I'll look at this kind of fragility at some point. Toby. Thanks Toby! scott ___ 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
Re: [JBoss-user] RE: Error 'closing' a pooled connection (addendum)
On Tue, May 15, 2001 at 04:11:27PM -0700, enter name here wrote: 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) Ok, you're missing out some details. Are you calling an EJB from a servlet? You haven't mentioned anything about what this EJB is doing. What are you doing with transactions? Are you getting the connection in the servlet and trying to close it from the EJB or something? A servlet calls the bean it only passes primitive types (int, float, etc) into the bean, the bean gets its own connections from the pool and closes everything itself - the servlet simply determines which bean to call and gets form parameters to pass into the bean, the results are returned from the bean and are formatted into HTML to display them. The results may be Map objects, or primitive types Ok, that should be fine. This is, in fact not a transactional bean. All it does is retrieves data from the database and shoves it into a Map to return. It is a session bean because some of the lookups are a little complex (do not map directly to a table) -- and some of them require multiple row lookups - which you cannot do with entity beans. Looking at the TxInterceptorBMT code, I suspect that you are getting a NoClassDefFoundError for the DatabaseUtility class. Do you have that class in your ejb-jar? Try catching Throwable around the call to DatabaseUtility and printing the stacktrace. Toby. ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user