Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds

Developing an EJB 3.0 entity in WebLogic Server

Save for later
  • 180 min read
  • 2010-08-27 00:00:00

article-image

(For more resources on Oracle, see here.)

Setting the environment

In the following sections, we will learn how to set up the environment.

Installing required products

First, download and install the following required products; when installing the MySQL database, select the option to add the MySQL bin directory to the Windows system PATH environment variable:

  1. Oracle WebLogic Server 11g (http://www.oracle.com/technology/software/products/ias/htdocs/wls_main.html).
  2. Oracle Enterprise Pack for Eclipse All-In-One edition (http://www.oracle.com/technology/software/products/oepe/oepe_11113.html).
  3. MySQL 5.x database (http://www.oracle.com/us/products/mysql/index.html).

Creating a MySQL database table

Next, create a database table in the MySQL database as follows:

  • Log in to the MySQL database with the following command:

    >mysql

  • Set database as test:
    mysql>use test
  • Run the following SQL script, which creates a Catalog table for the EJB 3 entity:
    CREATE TABLE Catalog (id INT PRIMARY KEY NOT NULL, 
    journal VARCHAR(100), publisher VARCHAR(100), date VARCHAR(100),
    title VARCHAR(100), author VARCHAR(100));

The output from the CREATE TABLE SQL script is shown in the following screenshot:

developing-ejb-30-entity-weblogic-server-img-0

The table description may be listed with the desc command, as shown in the following illustration:

developing-ejb-30-entity-weblogic-server-img-1

Configuring WebLogic Server with MySQL database

We shall be using a MySQL database for persistence. Therefore, we need to create a data source in WebLogic Server. Start the WebLogic Server and log in to the Administration Console.

Creating a data source

Select the base_domain | Services | JDBC | Data Sources. Click on New in the Data Sources table. Specify a data source name and a JNDI Name (jdbc/MySQLDS) for the data source. Select Database Type as MySQL and Database Driver as MySQL's Driver (Type 4): com.mysql.jdbc.Driver. Click on Next, as shown in the following screenshot:

developing-ejb-30-entity-weblogic-server-img-2

(Move the mouse over the image to enlarge.)

In the Transaction Options window, select Supports Global Transactions and One-Phase Commit. Click on Next, as shown in the following screenshot:

developing-ejb-30-entity-weblogic-server-img-3

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at $15.99/month. Cancel anytime

Specify the connection properties: Database Name as test, Host Name as localhost, Port as 3306, and Database User Name as root. Specify the Password used when installing MySQL and click on Next, as shown in the following screenshot:

developing-ejb-30-entity-weblogic-server-img-4

In the Test Database Connection window, the Driver Class Name and connection URL are specified, normally filled from the information you entered in the previous screen. Click on Test Configuration to test the connection. Click on Finish, as shown in the following screenshot:

developing-ejb-30-entity-weblogic-server-img-5

A data source gets added to the Data Sources table with its data source JNDI Name as jdbc/MySQLDS, as shown in the following screenshot:

developing-ejb-30-entity-weblogic-server-img-6

Deploying the data source

Next, we deploy the data source to a target server. Click on the data source link in the Data Sources table and select the Targets tab. Select the AdminServer checkbox and click on Save, as shown in the following screenshot:

developing-ejb-30-entity-weblogic-server-img-7

The target server changes get applied and saved:

developing-ejb-30-entity-weblogic-server-img-8

Testing the data source

To test the data source, click on Test Data Source. If the data source tests without an error, a message indicating the same gets displayed as shown next:

developing-ejb-30-entity-weblogic-server-img-9