Exercise 5.2: The EJBObject, Handle, and Primary Key

The example programs in Exercise 5.2 explore the APIs available through the EJBObject and EJBMetaData interfaces. They also reveal how to use Handle and HomeHandle as persistent references to EJB objects and homes.

Start Up JBoss

If you already have JBoss running, there is no reason to restart it. Otherwise, start it up as instructed in the JBoss Installation and Configuration chapter at the beginning of this workbook.

Initialize the Database

The database should contain the 100 rows created by a successful execution of the test programs from Exercise 4.1; otherwise, this example will not work properly.

Build and Deploy the Example Programs

In the ex05_2 directory, build and deploy the examples as you did for Exercise 5.1.

Examine the JBoss-Specific Files

There are no new JBoss configuration files or components in this exercise.

Examine and Run the Client Applications

Three example programs illustrate the concepts explained in the EJB book:

Client_52a.java

Shows the use of EJBObject to retrieve an EJB’s home interface.

Client _52b.java

Shows how to use isIdentical( ) to determine whether two EJB references are to the same object.

Client _52c.java

Shows how to use EJB handles as persistent bean references.

The example code is pulled directly from the EJB book and embellished somewhat to expand on introduced concepts. The EJB book does a pretty good job of explaining the concepts illustrated in the example programs, so further ...

Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.