Hi ALL I am a bit confused about EJBs opening connections to DB. I have 3 EJBs getting Connections from DataSource. EJB A gets a connection from Datasource, performs some DB operation and calls EJB B, EJB B does the same as EJB A and calls EJB C. When EJB C also accesses the DataSource to open connection, How many physical connections are opened to the DB or in otherwords How many active connections to DB am I using? Would it be 3 connections to DB, one for each EJB or only one connection is being used by the 3. All EJBs have Txn attribute "Required".
I think you will have opened 3 physical DB connections. Because each time you call getConnection() you get new connection (connections may be pooled inside container).
I think it would be better close connection before calling another EJB as you can go into deadlock (if container has DB pool). For example, your pool size is 5 connections and you have 2 free DB connection. EJB A calls getConnection(), the EJB B call getConnection(). And when EJB C call getConnection(), this EJB locks locks as DB pool doesn't have any free DB connection (as they č ones are used for EJB A and B). And only some time (pool timeout) this EJB get DB connection error and returns with exception.
So better is to keep DB connection as shorter as possible - read all data, close connection and only then call EJB B if possible.