ON CLIENT java.sql.SQLException: Connection handle has been closed and is unusable ON SERVER [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.WrappedConnection@594680
The problem is the that is in the apriConnessione() i got a call for make a db connection. This one is activated fist from ejbActivate(); then jboss close automatically connection without a ejbPassivate(). Then i enter in Interroga() method and the connection is no more avaible giving me exception.
In this case the program has no error. BUT I do not understand the beaviour of jboss because i studied that in ejbPassivate / ejbActivate i must close connections; not in every method! Reading the FAQ i understand that i must open & close connection in every method. Can you explain me why? .. or what i misunderstand thankyou, Bye
ejbActivate() and ejbPassivate() are called during instance pooling. ejbPassivate() invoked when instance is sent back to pool and ejbActivate when instance taken from pool. Its recommended to release resources being held by bean before its passivated and hence closing of database connection and while activating the bean instance from pool the database resource connection can be opened.
If the database connection is opened only in ejbActivate() method which is not neccessary invoked before some other method on bean instance is called ( for a simple reason that bean instance hasn't been passivated as yet)then in that case this other method will not have connection opened.
Yes i understand what you say but if a put a connection to database in the client as follow is not right as putting a connection inside a method in the bean?
class Client ...
sfjdbc.apriConnessione(); //method that in bean connect to Db
sfjdbc.interroga("select * from Cliente where COD_FISCALE = 'MRNFRZ68M29E463B'"); /*method that use the database, that give me error if do not put insit it the connections to db routines*/
sfjdbc.chiudiConnessione();//method that in bean disnect to Db
sfjdbc.remove(); ... }
In above code when you put connection inside client code, where are you storing the connection object, its still being stored in Session Bean and there you have declared this Connection object as transient type, so when the bean instance is passivated the Connection object value is not preserved. Also its recommended to release such resources when the bean instance is passivated and hence in your earlier code, the code to open n close Database connection in ejbActivate() and ejbPassivate() was justified.
The point is that you don't know when ejbActivate() and ejbPassivate() are called so its better if you open the database connection in interroga() and close it before coming out of this method. Closing a database connection only release the connection back to connection pooling and hence not an overhead if in each business methods its opened n closed again.