Lab 7 - Container-based Entity Beans

Milestone 3. due May 18, 11:59pm

In this lab you'll implement and use container-based entity beans. More specifically the following example demonstrates:

Part 1. You will set up a data source. Then you will deploy and run an example of entity beans. The source code is in /stage/classes/current/51024-1/pub/EJB/Product/.
The bean client creates 6 separate products (beans) and retrieves back some of them. Then it removes them all.

Steps:

  1. Configure a JDBC data source using Weblogic console.

    Create a data source with a name that includes your CS login name; for example: "myloginDataSource". Create a JNDI name for your data source (for example: myloginJDBCTxDataSource). Set up a JDBC connection to the Oracle database server using your Oracle account. The name of the database is cs51024. You can also see this by typing echo $ORACLE_DB.

    Documentation on JDBC data source configuration:

     - Create JDBC data sources

     - Configuring WebLogic JDBC Resources

    Enable the target "examplesServer" in the Settings section of your data source.

    Read the generated configuration file in $WL_HOME/samples/domains/wl_server/config/jdbc.If your data source name is "myloginDataSource", your JDBC data source configuration file should have a name like myloginDataSource-????-jdbc.xml.
    Read your server configuration file config.xml. What do you see? Where is your data source? Where are the deployed EJBs?

  2. Copy the example somewhere in your user space:
       
      $ mkdir <YOUR_DIR>
      $ cp -r /stage/classes/current/51024-1/pub/EJB/Product/ <YOUR_DIR>
       
    Modify the file weblogic-cmp-rdbms-jar.xml. Set data-source-name to the JNDI name you used for your data source.

  3. Compile:
        
    cd <YOUR_DIR>
          make
this will create a jar file ejb_product.jar (in $WL_HOME/samples/domains/wl_server/autodeploy/) that contains all  compiled code needed for your bean. It will also compile your client and put all .class file in the $CLIENT_CLASSES directory  ( this is already in your CLASSPATH).  Please take a look at the Makefile to understand what's going on. The build process is explained in more detail here.
  1. For this example you do not need to modify the deployment descriptors: ejb-jar.xml, weblogic-ejb-jar.xml or weblogic-cmp-rdbms-jar.xml but please take a look.  

    Notice in your deployment descriptors weblogic-cmp-rdbms-jar.xml the name of the table that will be used in this example. Please create this table with:

    create table Products (name varchar(50), productid varchar(50), description varchar(100), basePrice Integer)

  1. Find your deployed beans in the "Summary of Deployments" of the console. (Deployments->Monitoring->EJBs->Entity)
  2. You should see an entry with the EJB name Product. If you don't see this, go to Domain Structure-> Services->JDBC->Data Sources again and make sure you see the new data source that you have created in step 1. You may need to restart weblogic for some of the changes to take affect.
  3. Run the client with ./run_client.sh or:

    java -Djava.naming.factory.initial=weblogic.jndi.WLInitialContextFactory -Djava.naming.provider.url=t3://localhost:7001 examples.product.ProductClient

    What did change in the EJB monitor of the console?

Part 2


Work on Milestone 3: Implement your own entity beans that should take you closer to completing the final project.