Friday, February 29, 2008

EJB Primer with WSAD - Part 1

This is a step by step tutorial on building a simple EJB application, using Oracle as the BackEnd, primarily for newbies to EJB and WebSphere technologies. We will develop a complete Container Managed (CMP) EJB Application using WSAD - WebSphere Studio Application Developer Version 5.1.2, run and test it on a TestServer in the IDE, and later, package the application to an .ear file and deploy in WebSphere Application Server.


Click on the images to view them full size!



Step 1 - Create the Data Store

Create the table 'employees' with the following columns.

employeeid - number
firstname - varchar(25)
lastname - varchar(25)



Step 2 - Create the EJB and EAR Projects in WSAD

In WSAD file menu, click New->Project->EJB. Create 2.0 EJB Project. Type in the EJB project name as EmployeeEJB and the corresponding EAR project name as EmployeeEAR.





Step 3 - Create the CMP Entity Bean under EmployeeEJB Project

In the J2EE Hirarchy view, right click on EmployeeEJB project, and select New->Enterprise Bean.
Select EmployeeEJB as the EJB Project. In the next window, select CMP as the bean type having version 2.0 and type in the Bean Name as EmployeeEntity, and package name as employee.ejb.




Unselect the Local Client View check box, and Select the Remote Client View checkbox. This is to instruct WSAD to generate the Remote Interface and not to generate the Local Interfaces.
Now, add the persistant fields to the bean. Click the Add button under CMP Attributes and add the fields as below:

employeeid - int
firstname - String
lastname - String

Select 'Promote getter and setter methods to remote interface' to each field except employeeid. For employeeid, select the 'Key Field' option. After adding all fields, click Finish.



Step 4 - Create WebSphere Server

Click on the Server Perspective on the left side bar to open the Projects in the Server Perspective. I the Server configuration Pane, click on Servers->New->Server and Server Configuration.



Give the Server name - TestServer. Make sure that the Server Type is selected as 'Test Enviornment'. In the next page, note the HTTP port on which server would be listening. If you wish to change the port, change it here.




Go to : Part 1Part 2Part 3Part 4Part 5Part 6

No comments: