- EJB 3.0 Database Persistence with Oracle Fusion Middleware 11g
- Deepak Vohra
- 606字
- 2025-02-23 11:18:33
The Enterprise JavaBeans (EJB) 3.0 specification has facilitated the development of EJBs by providing an annotations-based API in which the remote/local and home/local home interfaces are not required. The deployment descriptors that form the basis of an EJB 2.0 entity bean are also not required for deploying an EJB 3.0 entity bean. In Chapter 1, we discussed the new features in EJB 3.0. This chapter covers the procedure to convert an EJB 2.0 Entity to an EJB 3.0 Entity.
The EJB 3.0 entity bean classes are simplified in comparison to the EJB 2.0 specification classes. The EJB 3.0 entity class is a Plain Old Java Object (POJO) instead of a class implementing the EntityBean
interface. The component interfaces in EJB 2.0, which were required to extend the EJBLocalObject/EJBObject
and home interfaces, which were required to extend the EJBLocalHome/EJBHome
interfaces, are replaced with the javax.persistence.EntityManager
API to create, find, and update entity bean instances.
We shall be creating an EJB 3.0 entity by transforming the EJB 2.0 deployment descriptor (ejb-jar.xml
) using XSL stylesheets. This chapter uses the built-in XSL transformation tool in Oracle JDeveloper 11g to provide the XSLT transformation for converting the EJB 2.0 entity deployment descriptor to the EJB 3.0 entity class. Download and install Oracle JDeveloper 11g from http://www.oracle.com/technology/software/products/middleware/index.html.
First, create a new application in JDeveloper. To do so, click on New Application, as shown next:

In the New Application wizard, specify an Application Name (for example EJB2toEJB3
). Select Application Template as Generic Application and click on Next, as shown in the following screenshot:

Next, specify a Project Name (EJB2toEJB3
for example). Select XML as a project technology and click on Finish.

An application and a project get added to the Application Navigator, as shown next:

Next, we create an XML document for the EJB 2.0 entity deployment descriptor, which is to be converted to anEJB 3.0 entity. We shall also create EJB 3.0 Session bean façade classes from the deployment descriptor. Select File | New and in the New Gallery window select Categories:General | XML. From the Items: window, select XML Document and click on OK.

In the Create XML File window, specify a File Name (ejb-jar-modified.xml
). We shall be using a slightly modified ejb-jar.xml
, as the deployment descriptor does not contain all the required information to convert an EJB 2.0 entity to an EJB 3.0 entity. Click on OK.

We also need to create the XSL stylesheets to transform the EJB 2.0 entity deployment descriptor to EJB 3.0 entity class and façade classes. In the New Gallery window, select Categories:General | XML and Items:XSL Style Sheet and click on OK.

In the Create XSL File window specify an XSL File Name (entity-bean.xsl
) and click on OK. The XSL version is set to XSL 2.0 by default.

The XSL stylesheet entity-bean.xsl
gets added to the EJB2toEJB3
project. The following illustration shows the stylesheet copied from a later listing in this chapter.

Similarly, add XSL stylesheets façade.xsl
and façade-bean.xsl
to generate EJB 3.0 façade classes with.

To test that the EJB 3.0 entity classes generated using XSL transformation comply with the EJB 3.0 API, add libraries EJB 3.0, Java EE 1.5, and Java EE 1.5 API to the project in the Project Properties window. First, select Tools | Project Properties. Subsequently, add the required libraries with the Add Library button. These libraries are pre-configured in JDeveloper and only need to be selected and added. Click on OK.
