Search This Blog

Thursday, October 20, 2005

Creating and Working with an Entity CMP Bean in IBM WebSphere

Last week we worked with session beans in IBM WEBSPHERE. This week lets learn to create and work with an Entity CMP Bean.

STEP 1:
---------

First Create a Project J2EE Application project..that i have covered already in my last BLOG. I have named my project get.

After i click finish i get 3 files

a.)get
b.)getEJB
c.)getWEB

STEP 2:
---------

Next go to J2EE Hierarchy and Click on EJB Module

Click on getEJB then go to Entity Beans and Right Click and click on NEW Click on CMP Bean.


After this....

U will get New Enterprise Bean Screen here select the EJB Project for which u wan to create th Entity CMP Bean...in this case it is getEJB.


After this u will get a screen where u must name your bean..here the bean should be given the same name as your database table. Regarding this we need some classification.


Next u will get a screen where u must tick the include Remote Client View.


In this view itself u also have the option to add CMP Attributes.

I have added to attributes uname of type String and id of type int.
Next click on next and Finish.



STEP 3
--------

Double click on add in Queries and add a query that you will use.

Here i will retrieve the uname and provide the id as Paramater. Uname is my username and id my id.



Also select the Return Type...which in this case is com.login


Next click on Select a simple Query...here have selected
Find All Query which will select all data from the database.


Click on Finish

STEP 4 --------

Next we have to add EJB TO RDB Mapping which will map your EJB TO DATABASE.

For this come to EJB Module Right CLICK on Generate then select EJB TO RDB mapping.
Next in EJB TO RDB Mapping select Create a new Backened Folder and click next

Next u will get another screen here select Meet in the Middle.


Next u must give the connection name which is the Database Name in this case ecart.

Next Name the Database which is Ecart the UserId which is your db2admin username and Password which is db2admin for your db2admin.

Select Database Vendor Type which is DB2 Universal Database v7.1

Next u will get a List of DB2 Table here select the Table u will work with. I am working with Login table.

Next select Match ByName and Type

Click on Finish.

STEP 5
-------

Click on Project Navigator and select We Deployement Descriptor then go to
Web Library Projects here add JAR NAME AND create jar i have added getejb.JAR.

Now save your Space...that's is all u do now call your ejb from any JSP or servlet.

No comments: