hen building a large-scale J2EE/Java EE application, developers have a few options for establishing database (DB) connectivity from EJBs, including handling it transparently using a J2EE data source, or encapsulating JDBC details inside a Data Access Object (DAO) or inside a single class from which all session beans retrieve the DB connections. However, when using Oracle Containers for J2EE (OC4J), many enterprise Java developers establish a data-sources configuration through the EJB framework by using session beans with bean-managed persistence.
The problem with this approach, which establishes/retrieves a connection from the connection pool in the ejbCreate() method and releases it in ejbRemove(), is that when developers apply it to large applications with hundredsor even thousandsof stateless session beans, database connections can get held up and eventually become stale (see Sidebar 1. Retaining a DB Connection Throughout a Stateless Session Bean's Lifecycle). Consequently, when session beans try to process an application's service request using a stale DB connection, the user sees unusual errors. They need to restart the application server to resolve the problem.
Oracle Application Server 10g Release 3 (10.1.3) addresses this challenge with the introduction of DB Connection Manager and OC4J's implicit connection caching mechanism. This article details the features of this mechanism, which enables managed data source configuration, and its benefits to existing J2EE applications. While the discussion details using Oracle Application Server 10g, J2EE/Java EE-compliant app servers can also provide this feature by using the latest OC4J Oracle JDBC libraries.