官术网_书友最值得收藏!

Chapter 2. Converting an EJB 2.0 Entity to an EJB 3.0 Entity

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.

Setting the environment

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.

Adding an Application

First, create a new application in JDeveloper. To do so, click on New Application, as shown next:

Adding an Application

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:

Adding an Application

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

Adding an Application

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

Adding an Application

Creating an XML deployment descriptor

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.

Creating an XML deployment descriptor

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.

Creating an XML deployment descriptor

Creating stylesheets

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.

Creating stylesheets

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.

Creating stylesheets

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.

Creating stylesheets

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

Creating stylesheets

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.

Creating stylesheets
主站蜘蛛池模板: 长阳| 衡阳市| 于田县| 富源县| 蒙山县| 丹寨县| 南宁市| 泗阳县| 阿拉善右旗| 汝州市| 仙游县| 白山市| 仁布县| 阳信县| 台北县| 习水县| 宁南县| 太原市| 德江县| 冕宁县| 英吉沙县| 濮阳县| 油尖旺区| 抚顺市| 华亭县| 平和县| 英德市| 永福县| 桂东县| 镇原县| 温泉县| 萨迦县| 哈巴河县| 平定县| 澄迈县| 江城| 读书| 扎囊县| 石屏县| 聂拉木县| 威远县|