How to configure weblogic for BMP and Connection Pool


EJB design: How to configure weblogic for BMP and Connection Pool

  1. Hi Friends,

    If i use BMP, i m not able to access oracle pool, when i run my client, gives ejbException and it is not able to access the pool. ple help me. if i use CMP it is working fine.

  2. There is no relationship between BMP and using Connection Pool. U should implement all ejb Methods that is automatically done in CMP.
    If u are developing in Visualcafe all Descriptors are written by the VCafe...if u have problem mail me at
  3. Hi Satya,
       In the case of BMP u r going to write the data access layer for ur bean using JDBC api's. Before performing each DB operation u require an instance of java.sql.Connection object. For example the ejbCreate() method will look like:

       // globally defined variables
       public Connection con;
       public EntityContext ec;

       public void setEntityContext(EntityContext ec) {
  = ec;

           // populating con with a valid connection
           // DB Driver ==> sun.jdbc.odbc.JdbcOdbcDriver
           // DB URL ==> jdbc:odbc:myDSN

           con = DriverManager.getConnection(

       public String ejbCreate(String id, String name)
              throws CreateException, SQLException {
           Statement st = con.createStatement();
           int c = st.executeUpdate("insert into employee
                      value (" + id + "," + name + ")");


    Inside the setEntityContext() method, there are *3* ways of populating (instantiating) the "con" object:

    1. Hard-coding of url and driver names:
          This is what i've done in the above code. but *never* do this, since our bean loses it's "Generic" nature.

    2. specifying url and driver names as <env-entry> in the bean's DD's (2 in case of weblogic):
          This is somewhat acceptable way of specifying the url and driver name for a particular DB that we are going to access from inside our entity bean.
          for example the env-entry for driver looks like:
                  <env-entry-name>DB DRIVER</....>

              <!-- Similar entry for "DB URL" -->

         Now the setEntityContext() method will look like:

         public void setEntityContext(EntityContext ec)
                throws NamingException {
    = ec;

             Context ctx = new InitialContext();
             String driver = (String) ctx.lookup
                                 ("java:comp/env/DB DRIVER");
             String url = (String) ctx.lookup
                                 ("java:comp/env/DB URL");
             con = DriverManager.getConnection(url);

    In both of the above methods (1 & 2), it is the responsibility of the bean instance to instantiate a "con" object whenever it (bean) gets created by the container. Why not make use of the connections that are already pooled and readily available to it (bean) from the container's "connection pool" that u've created during server startup??. The answer to this question is the third method of populating "con" object from inside ur bean instance. This will give improved performance and high scalability.

    3. How to do this? (continued as next message in the thread)

  4. ....continued from previous message :-)

    a. file:-
        (i) During server startup u r creating a connection pool for ur database with some name, say, "oraclePool".
        (ii) This pool is a resource that is now available with the server and the container can make use of it. Even this resource is a java object and it can be bound to the "naming service" that is running in that server. The binding of this object (connection pool resource) is done with the help of giving this line in ur file:


    In the above line, "weblogic.jdbc.TXDataSource" is the property name. "weblogic.jdbc.jts.pool" is the JNDI name with which our object (oraclePool) is going to get bound to the naming service.

    b. ejb-jar.xml file:-

       Add the following tags to ur ejb-jar.xml file...


    only with this name, "jdbc/oraclePool" we'll be getting a reference to our oraclePool resource from inside the bean. The type of that resource is "javax.sql.DataSource".

    c. weblogic-ejb-jar.xml file:-

        Add the following tags to ur weblogic-ejb-jar.xml file..


    Here we r making association between what we've given in the first xml file and the JNDI name for the resource, "weblogic.jdbc.jts.pool" (Step 'a'). This association is thru the tag <res-ref-name> (jdbc/oraclePool).

    d. ur bean class:-

    now the setEntityContext() method will look like:

         public void setEntityContext(EntityContext ec)
                throws NamingException {
    = ec;

             Context ctx = new InitialContext();
             DataSource ds = (DataSource) ctx.lookup
             con = ds.getConnection();
    Hope this has given u enough input of how to make use of the connections that r've already pooled, from ur BMP entity bean. mail me once u've solved the problem.

    (ahamed at aztec dot soft dot net)
  5. Thanx a lot, Ahmed Hasan and Saurav for your kind help.
  6. I can ask for difference between that above and this

      Context ctx = new InitialContext();
      DataSource ds = (DataSource)ctx.lookup("weblogic.jdbc.jts.oraclePool");

     it is simple, isn't it.